﻿namespace = ep3_frankokratia_events

# Your relative, a Byzantine claimant, approaches you about redirecting the crusade... the pope chooses whether to reply with condemnation or support
ep3_frankokratia_events.0001 = {
	type = character_event
	title = ep3_frankokratia_events.0001.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					faith.great_holy_war = {
						any_pledged_attacker = {
							this = root
						}
					}
				}
				desc = ep3_frankokratia_events.0001.crusader_intro
			}
			desc = ep3_frankokratia_events.0001.non_crusader_intro
		}
		desc = ep3_frankokratia_events.0001.desc
	}

	theme = byzantine
	override_background = {
		trigger = {
			faith.great_holy_war = {
				any_pledged_attacker = {
					this = root
				}
			}
		}
		reference = docks
	}
	override_background = {
		trigger = {
			NOT = {
				faith.great_holy_war = {
					any_pledged_attacker = {
						this = root
					}
				}
			}
		}
		reference = temple
	}
	override_effect_2d = {
		reference = rain
	}
	left_portrait = {
		character = root
		animation = inspect_weapon
	}

	right_portrait = {
		character = scope:byz_claimant
		animation = prayer
		camera = camera_event_right_forward
	}

	lower_right_portrait = {
		character = scope:byz_emperor
	}

	lower_left_portrait = {
		character = scope:ghw_sponsor
	}

	trigger = {
		exists = root.faith.great_holy_war
		exists = root.faith.religious_head
		exists = title:e_byzantium.holder
		ep3_frankokratia_story_owner_trigger = yes
		root.faith.great_holy_war = {
			ep3_frankokratia_ghw_trigger = yes
		}
		ep3_frankokratia_financier_exists_trigger = yes
	}
	on_trigger_fail = {
		if = {
			limit = {
				NOT = {
					has_character_flag = tried_franko_start
				}
			}
			add_character_flag = {
				flag = tried_franko_start
				years = 1
			}
		}
		else_if = {
			limit = {
				NOT = {
					has_character_flag = tried_franko_start_2
				}
			}
			add_character_flag = {
				flag = tried_franko_start_2
				years = 1
			}
		}
		else = {
			add_character_flag = {
				flag = tried_franko_start_3
				years = 1
			}
		}
		#Re-try triggering the event twice
		if = {
			limit = {
				basic_is_valid_for_yearly_events_trigger = no
				NOT = {
					has_character_flag = tried_franko_start_3
				}
			}
			trigger_event = {
				id = ep3_frankokratia_events.0001
				days = 30
			}
		}
	}
	immediate = {
		save_scope_as = byz_claimant_champion
		root.faith.religious_head = { save_scope_as = ghw_sponsor }
		#Start with close family in your court/realm
		random_close_family_member = {
			limit = {
				OR = {
					is_courtier_of = prev
					is_vassal_of = prev
					is_pool_guest_of = root
				}
				ep3_frankokratia_claimant_trigger = yes
			}
			save_scope_as = byz_claimant
		}
		#Spouses
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_spouse = {
				limit = {
					ep3_frankokratia_claimant_trigger = yes
				}
				save_scope_as = byz_claimant
			}
		}
		#Soulmate
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_relation = {
			 	type = soulmate
			 	limit = {
			 		ep3_frankokratia_claimant_trigger = yes
			 	}
			 	save_scope_as = byz_claimant
			}
		}
		#FRIENDS
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_relation = {
			 	type = friend
			 	limit = {
			 		ep3_frankokratia_claimant_trigger = yes
			 	}
			 	save_scope_as = byz_claimant
			}
		}
		#Spouses of close family in your court/realm
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_close_family_member = {
				limit = {
					OR = {
						is_courtier_of = root
						is_vassal_of = root
						is_pool_guest_of = root
					}
					ep3_frankokratia_transiting_relative_trigger = yes
					any_spouse = {
						ep3_frankokratia_claimant_trigger = yes
					}
				}
				random_spouse = {
					limit = {
						ep3_frankokratia_claimant_trigger = yes
					}
					save_scope_as = byz_claimant
				}
			}
		}
		#Close family of spouses
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_spouse = {
				limit = {
					ep3_frankokratia_transiting_relative_trigger = yes
					any_close_family_member = {
						ep3_frankokratia_claimant_trigger = yes
					}
				}
				random_close_family_member = {
					limit = {
						ep3_frankokratia_claimant_trigger = yes
					}
					save_scope_as = byz_claimant
				}
			}
		}
		#Courtier or guest, unrelated
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_courtier_or_guest = {
				limit = {
					is_foreign_court_guest = no
					ep3_frankokratia_claimant_trigger = yes
				}
				save_scope_as = byz_claimant
			}
		}
		#Close or extended family anywhere
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_close_or_extended_family_member = {
				limit = {
					ep3_frankokratia_claimant_trigger = yes
				}
				save_scope_as = byz_claimant
			}
		}
		#Pool characters
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_pool_character = {
			 	province = root.capital_province
			 	limit = {
			 		ep3_frankokratia_claimant_trigger = yes
			 	}
			 	save_scope_as = byz_claimant
			}
		}
		#In-laws anywhere
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_close_or_extended_family_member = {
				limit = {
					ep3_frankokratia_transiting_relative_trigger = yes
					any_spouse = {
						ep3_frankokratia_claimant_trigger = yes
					}
				}
				random_spouse = {
					limit = {
						ep3_frankokratia_claimant_trigger = yes
					}
					save_scope_as = byz_claimant
				}
			}
		}
		#In-laws of family anywhere
		if = {
			limit = {
				NOT = { exists = scope:byz_claimant }
			}
			random_close_family_member = {
				limit = {
					ep3_frankokratia_transiting_relative_trigger = yes
					any_spouse = {
						ep3_frankokratia_transiting_relative_trigger = yes
						any_close_family_member = {
							ep3_frankokratia_claimant_trigger = yes
						}
					}
				}
				random_spouse = {
					limit = {
						ep3_frankokratia_transiting_relative_trigger = yes
						any_close_family_member = {
							ep3_frankokratia_claimant_trigger = yes
						}
					}
					random_close_family_member = {
						limit = {
							ep3_frankokratia_claimant_trigger = yes
						}
						save_scope_as = byz_claimant
					}
				}
			}
		}
		#Save Byzantine emperor
		title:e_byzantium.holder = {
			save_scope_as = byz_emperor
		}
		#Save a financier for this wild venture
		ep3_frankokratia_save_financier_effect = yes
	}
	#You go ahead with your plan by privately getting support
	option = {
		name = ep3_frankokratia_events.0001.b
		flavor = ep3_frankokratia_events.0001.b.flavor
		custom_tooltip = abandon_crusade_tooltip
		custom_tooltip = byz_claimant_crusade_tooltip
		custom_tooltip = may_form_latin_empire_tooltip
		custom_tooltip = crusaders_may_be_paid_tooltip
		create_story = frankokratia_story
		random_owned_story = {
			type = frankokratia_story
			ep3_frankokratia_story_setup_save_vars_effect = yes
		}
		if = {
			limit = {
				scope:byz_claimant = {
					NOR = {
						is_courtier_of = root
						is_ruler = yes
						any_spouse = {
							is_ai = no
							this != root
						}
					}
				}
			}
			add_courtier = scope:byz_claimant
		}
		if = {
			limit = {
				scope:byz_claimant = {
					NOT = {
						has_claim_on = title:e_byzantium
					}
				}
			}
			add_unpressed_claim = title:e_byzantium
		}

		add_character_modifier = {
			modifier = prepared_for_daring_deeds_modifier
			years = 3
		}
		hidden_effect = {
			scope:byz_claimant = {
				add_character_modifier = {
					modifier = eager_for_empire_modifier
					years = 5
				}
			}
		}

		#Pope eventually finds out and is annoyed at you
		trigger_event = {
			id = ep3_frankokratia_events.0002
			days = { 6 8 }
		}
		#Financier gets on board
		trigger_event = {
			id = ep3_frankokratia_events.0003
			months = { 1 3 }
		}

		stress_and_fulfillment_impact = {
			zealous = major_stress_impact_gain
			trusting = medium_stress_impact_gain
			just = major_stress_impact_gain
			humble = medium_stress_impact_gain
			content = medium_stress_impact_gain
		}

		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_zeal = -1
				ai_rationality = -1
				ai_boldness = 1
				ai_honor = -1
				ai_energy = 1
			}
			modifier = {
				factor = 0.5
				OR = {
					has_trait = honest
					has_trait = diligent
					has_trait = lazy
					has_trait = craven
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = zealous
					has_trait = content
					has_trait = trusting
					has_trait = just
					has_trait = humble
					has_trait = loyal
				}
			}
		}
	}
	#You attempt to convince the Pope to support your plan
	option = {
		name = ep3_frankokratia_events.0001.a
		flavor = ep3_frankokratia_events.0001.a.flavor


		custom_tooltip = abandon_crusade_tooltip
		custom_tooltip = byz_claimant_crusade_tooltip
		custom_tooltip = may_form_latin_empire_tooltip
		custom_tooltip = crusaders_may_be_paid_tooltip
		if = {
			limit = {
				scope:byz_claimant = {
					NOR = {
						is_courtier_of = root
						is_ruler = yes
						any_spouse = {
							is_ai = no
							this != root
						}
					}
				}
			}
			add_courtier = scope:byz_claimant
		}
		if = {
			limit = {
				scope:byz_claimant = {
					NOT = {
						has_claim_on = title:e_byzantium
					}
				}
			}
			scope:byz_claimant = { add_unpressed_claim = title:e_byzantium }
		}
		duel = {
			skill = diplomacy
			value = decent_skill_rating
			50 = { #The Pope agrees on condition of "mending the schism"
				desc = ep3_frankokratia_events.0001.a.success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -49
				}
				modifier = {
					piety_level >= 3
					add = 30
				}
				modifier = {
					scope:ghw_sponsor.ai_boldness > low_positive_ai_value
					factor = 1.33
				}
				modifier = {
					scope:ghw_sponsor.ai_greed > low_positive_ai_value
					factor = 1.33
				}
				modifier = {
					scope:ghw_sponsor.ai_rationality < low_negative_ai_value
					factor = 1.33
				}
				modifier = {
					scope:ghw_sponsor.ai_honor < low_negative_ai_value
					factor = 1.33
				}
				custom_tooltip = more_crusaders_will_join_tooltip
				show_as_tooltip = {
					add_piety = medium_piety_gain
					if = {
						limit = {
							scope:byz_claimant.faith = {
								NOT = { this = faith:catholic }
							}
						}
						scope:byz_claimant = {
							set_character_faith = faith:catholic
						}
					}
				}
				scope:byz_claimant = { add_character_flag = swore_to_convert_byz_catholic }
				add_character_flag = {
					flag = pope_endorsed_crusader_claim
					years = 10
				}
				trigger_event = {
					id = ep3_frankokratia_events.0002
					days = 1
				}
			}
			50 = { #The Pope tries to condemns the plan
				desc = ep3_frankokratia_events.0001.a.failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -49
				}
				modifier = {
					scope:ghw_sponsor.ai_greed < low_negative_ai_value
					factor = 1.33
				}
				modifier = {
					scope:ghw_sponsor.ai_zeal > low_positive_ai_value
					factor = 1.33
				}
				modifier = {
					scope:ghw_sponsor.ai_rationality > low_positive_ai_value
					factor = 1.33
				}
				modifier = {
					scope:ghw_sponsor.ai_honor > low_positive_ai_value
					factor = 1.33
				}
				modifier = {
					piety_level <= 0
					add = 30
				}
				custom_tooltip = fewer_crusaders_will_join_tooltip
				show_as_tooltip = {
					add_piety_level = -1
					reverse_add_opinion = {
						modifier = angry_opinion
						target = scope:ghw_sponsor
						opinion = -50
					}
				}
				add_character_flag = {
					flag = pope_condemned_crusader_claim
					years = 10
				}
				trigger_event = {
					id = ep3_frankokratia_events.0002
					days = 1
				}
			}
		}
		hidden_effect = {
			scope:byz_claimant = {
				add_character_modifier = {
					modifier = eager_for_empire_modifier
					years = 5
				}
			}
		}

		add_character_modifier = {
			modifier = prepared_for_daring_deeds_modifier
			years = 3
		}


		stress_and_fulfillment_impact = {
			just = minor_stress_impact_gain
			content = medium_stress_impact_gain
			cynical = major_stress_impact_gain
		}

		ai_chance = {
			base = 150
			ai_value_modifier = {
				ai_zeal = 0.5
				ai_rationality = -1
				ai_boldness = 1
				ai_honor = -1
				ai_energy = 0.5
			}
			modifier = {
				add = 33
				scope:ghw_sponsor.ai_boldness > low_positive_ai_value
			}
			modifier = {
				add = 33
				scope:ghw_sponsor.ai_greed > low_positive_ai_value
			}
			modifier = {
				add = 33
				scope:ghw_sponsor.ai_rationality < low_negative_ai_value
			}
			modifier = {
				add = 33
				scope:ghw_sponsor.ai_honor < low_negative_ai_value
			}
			modifier = {
				add = -33
				scope:ghw_sponsor.ai_greed < low_negative_ai_value
			}
			modifier = {
				add = -33
				scope:ghw_sponsor.ai_zeal > low_positive_ai_value
			}
			modifier = {
				add = -33
				scope:ghw_sponsor.ai_rationality > low_positive_ai_value
			}
			modifier = {
				add = -33
				scope:ghw_sponsor.ai_honor > low_positive_ai_value
			}
			modifier = {
				add = -66
				diplomacy < decent_skill_rating
			}
			modifier = {
				add = 66
				diplomacy > extremely_high_skill_rating
			}
			modifier = {
				factor = 0.5
				OR = {
					has_trait = just
					has_trait = loyal
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = content
					has_trait = cynical
					diplomacy < low_skill_rating
				}
			}
		}
	}

	#This is a disastrously bad plan
	option = {
		name = ep3_frankokratia_events.0001.c
		flavor = ep3_frankokratia_events.0001.c.flavor
		add_piety = minor_piety_gain
		reverse_add_opinion = {
			target = scope:byz_claimant
			modifier = disappointed_opinion
			opinion = -40
		}
		if = {
			limit = {
				scope:byz_claimant = {
					is_courtier_of = root
				}
			}
			remove_courtier_or_guest = scope:byz_claimant
			if = {
				limit = {
					root.faith.great_holy_war = {
						any_pledged_attacker = {
							in_diplomatic_range = root
							ai_rationality <= low_positive_ai_value
						}
					}
				}
				root.faith.great_holy_war = {
					random_pledged_attacker = {
						limit = {
							in_diplomatic_range = root
							ai_rationality <= low_positive_ai_value
						}
						scope:byz_claimant = {
							visit_court_of = prev
						}
					}
				}
			}
		}

		stress_and_fulfillment_impact = {
			greedy = major_stress_impact_gain
			ambitious = major_stress_impact_gain
			fickle = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
		}

		ai_chance = {
			base = 0
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_boldness = -0.5
				ai_honor = 0.5
				ai_energy = -0.5
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = ambitious
					has_trait = fickle
					has_trait = arbitrary
				}
			}
		}
	}
}

#Reaction letter from the Pope
ep3_frankokratia_events.0002 = {
	type = letter_event
	opening = {
		desc = ep3_frankokratia_events.0002.opening
	}
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = pope_condemned_crusader_claim
				}
				desc = ep3_frankokratia_events.0002.desc_condemns
			}
			triggered_desc = {
				trigger = {
					has_character_flag = pope_endorsed_crusader_claim
				}
				desc = ep3_frankokratia_events.0002.desc_endorses
			}
			desc = ep3_frankokratia_events.0002.desc_wasnt_asked
		}
	}

	sender = scope:ghw_sponsor

	trigger = {
		exists = faith:catholic.religious_head
	}

	immediate = {
		title:e_byzantium.holder = {
			save_scope_as = byz_emperor
		}
	}
	#Whatever, Popey
	option = {
		name = ep3_frankokratia_events.0002.a
		custom_tooltip = continue_frankokratia_crusade_tooltip
		#Begin the story cycle if you asked for pope's approval
		if = {
			limit = {
				has_variable = {
					name = pope_condemned_crusader_claim
					name = pope_endorsed_crusader_claim
				}
			}
			create_story = frankokratia_story
			random_owned_story = {
				type = frankokratia_story
				ep3_frankokratia_story_setup_save_vars_effect = yes
			}
			#Financier gets on board
			trigger_event = {
				id = ep3_frankokratia_events.0003
				months = { 1 3 }
			}
		}
		#Visible effects
		if = {
			limit = {
				has_character_flag = pope_condemned_crusader_claim
			}
			custom_tooltip = fewer_crusaders_will_join_tooltip
			add_piety_level = -1
			reverse_add_opinion = {
				modifier = angry_opinion
				target = scope:ghw_sponsor
				opinion = -50
			}
		}
		else_if = {
			limit = {
				has_character_flag = pope_endorsed_crusader_claim
			}
			custom_tooltip = more_crusaders_will_join_tooltip
			add_piety = medium_piety_gain
			if = {
				limit = {
					scope:byz_claimant.faith = {
						NOT = { this = faith:catholic }
					}
				}
				scope:byz_claimant = {
					set_character_faith = faith:catholic
				}
			}
		}
		else = {
			reverse_add_opinion = {
				modifier = disrespect_opinion
				target = scope:ghw_sponsor
				opinion = -15
			}
		}
		if = {
			limit = {
				has_character_flag = pope_condemned_crusader_claim
			}
			stress_and_fulfillment_impact = {
				zealous = medium_stress_impact_gain
				trusting = minor_stress_impact_gain
				just = medium_stress_impact_gain
				craven = medium_stress_impact_gain
				humble = minor_stress_impact_gain
			}
		}

		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 1
				ai_boldness = 1
				ai_rationality = -1
			}
			modifier = {
				add = -25
				OR = {
					has_trait = trusting
					has_trait = humble
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = zealous
					has_trait = just
					has_trait = craven
				}
			}
		}
	}
	#Pope condemned me? I'm not going to go for it
	option = {
		trigger = {
			has_character_flag = pope_condemned_crusader_claim
		}
		name = ep3_frankokratia_events.0002.b
		custom_tooltip = end_frankokratia_crusade_war_tooltip
		#Reverse effects of prior event because you aren't going on an adventure
		add_piety = minor_piety_gain
		reverse_add_opinion = {
			target = scope:byz_claimant
			modifier = disappointed_opinion
			opinion = -40
		}
		if = {
			limit = {
				scope:byz_claimant = {
					is_courtier_of = root
				}
			}
			remove_courtier_or_guest = scope:byz_claimant
			if = {
				limit = {
					root.faith.great_holy_war = {
						any_pledged_attacker = {
							in_diplomatic_range = root
							ai_rationality <= low_positive_ai_value
						}
					}
				}
				root.faith.great_holy_war = {
					random_pledged_attacker = {
						limit = {
							in_diplomatic_range = root
							ai_rationality <= low_positive_ai_value
						}
						scope:byz_claimant = {
							visit_court_of = prev
						}
					}
				}
			}
		}
		remove_character_modifier = prepared_for_daring_deeds_modifier
		hidden_effect = {
			scope:byz_claimant = {
				remove_character_modifier = eager_for_empire_modifier
			}
		}
		remove_character_flag = pope_condemned_crusader_claim
		stress_and_fulfillment_impact = {
			stubborn = medium_stress_impact_gain
			eccentric = minor_stress_impact_gain
			brave = minor_stress_impact_gain
			arrogant = major_stress_impact_gain
			ambitious = medium_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -1
				ai_boldness = -1
				ai_rationality = 1
			}
			modifier = {
				add = -25
				OR = {
					has_trait = eccentric
					has_trait = brave
					has_trait = greedy
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = stubborn
					has_trait = arrogant
					has_trait = ambitious
				}
			}
		}
	}
}

#Sponsor wants money and sees your claimant as a good option
ep3_frankokratia_events.0003 = {
	type = letter_event
	opening = {
		desc = ep3_frankokratia_events.0003.opening
	}
	desc = ep3_frankokratia_events.0003.desc

	sender = scope:financier

	immediate = {
		title:e_byzantium.holder = {
			save_scope_as = byz_emperor
		}
	}
	#Alright, let's do this thing
	option = {
		name = ep3_frankokratia_events.0003.a

		custom_tooltip = financier_will_join_claim_war_tooltip
		custom_tooltip = will_give_byz_lands_tooltip
		custom_tooltip = every_ally_will_gain_modifier_tooltip

		scope:financier = { add_character_flag = joining_frankokratia }
		random_owned_story = {
			type = frankokratia_story
			add_to_variable_list = {
 				name = frankokratia_leaders
 				target = scope:financier
			}
		}
		set_global_variable = {
			name = financier_title
			value = scope:financier.primary_title
		}

		#Fire emperor warning event
		title:e_byzantium.holder = {
			trigger_event = {
				id = ep3_frankokratia_events.0004
				months = 1
			}
		}

		ai_chance = {
			base = 100
		}
	}
}

#Emperor learns of what's to come
ep3_frankokratia_events.0004 = {
	type = character_event
	title = ep3_frankokratia_events.0004.t
	desc = ep3_frankokratia_events.0004.desc
	theme = byzantine
	override_effect_2d = {
		reference = rain
	}
	override_background = {
		reference = docks
	}

	right_portrait = {
		character = scope:byz_claimant
		animation = inspect_weapon
		camera = camera_event_center
	}
	lower_right_portrait = {
		character = scope:byz_claimant_champion
	}
	lower_center_portrait = {
		character = scope:financier
	}
	cooldown = {
		years = 1
	}
	trigger = {
		is_alive = yes
		any_held_title = {
			this = title:e_byzantium
		}
		exists = global_var:byz_claimant_champion
		global_var:byz_claimant_champion = {
			any_owned_story = {
				type = frankokratia_story
			}
		}
	}
	on_trigger_fail = {
		if = {
			limit = {
				exists = title:e_byzantium.holder
				exists = global_var:byz_claimant_champion
				global_var:byz_claimant_champion = {
					any_owned_story = {
						type = frankokratia_story
					}
				}
			}
			title:e_byzantium.holder = {
				trigger_event = ep3_frankokratia_events.0004
			}
		}
	}
	option = {
		trigger = {
			is_ai = no
			OR = {
				has_trait = sadistic
				has_trait = callous
				has_trait = deceitful
				has_trait = craven
				has_trait = vengeful
				has_trait = arbitrary
				has_trait = lazy
				has_trait = paranoid
				has_trait = wrathful
				has_trait = cynical
			}
			can_start_scheme = {
				type = murder
				target_character = scope:byz_claimant
			}
		}
		name = ep3_frankokratia_events.0004.a
		flavor = ep3_frankokratia_events.0004.a.flavor
		start_scheme = {
			type = murder
			target_character = scope:byz_claimant
		}
		custom_tooltip = abandon_crusade_emp_tooltip
		custom_tooltip = franko_emp_crusade_tooltip
		custom_tooltip = byz_empire__destroyed_tooltip
		stress_and_fulfillment_impact = {
			just = medium_stress_impact_gain
			honest = medium_stress_impact_gain
			compassionate = major_stress_impact_gain
		}
	}
	option = {
		name = ep3_frankokratia_events.0004.b
		flavor = ep3_frankokratia_events.0004.b.flavor
		custom_tooltip = abandon_crusade_emp_tooltip
		custom_tooltip = franko_emp_crusade_tooltip
		custom_tooltip = byz_empire__destroyed_tooltip
		stress_and_fulfillment_impact = {
			craven = medium_stress_impact_gain
			paranoid = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
		}
	}
}

ep3_frankokratia_events.0005 = {
	type = letter_event
	opening = {
		desc = ep3_frankokratia_events.0005.opening
	}
	desc = ep3_frankokratia_events.0005.desc

	sender = scope:invalidation_sender

	immediate = {
		faith:catholic.religious_head = {
			save_scope_as = invalidation_sender
		}
		global_var:byz_claimant_champion = {
			random_owned_story = {
				type = frankokratia_story
				var:byz_claimant = {
					save_scope_as = claimant
				}
			}
		}
	}
	#Alright, it's over
	option = {
		name = ep3_frankokratia_events.0005.a

		custom_tooltip = frankokratia_story_ends_tooltip
		if = {
			limit = {
				any_owned_story = {
					type = frankokratia_story
				}
			}
			ep3_frankokratia_end_story_effect = yes
		}
		ai_chance = {
			base = 100
		}
	}
}

#Other rulers commit to your plan
ep3_frankokratia_events.0020 = {
	type = character_event
	title = ep3_frankokratia_events.0020.t
	desc = {
		desc = ep3_frankokratia_events.0020.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:redirecter = {
						has_character_flag = pope_condemned_crusader_claim
					}
				}
				desc = ep3_frankokratia_events.0020.pope_condemns
			}
			triggered_desc = {
				trigger = {
					scope:redirecter = {
						has_character_flag = pope_endorsed_crusader_claim
					}
				}
				desc = ep3_frankokratia_events.0020.pope_endorses
			}
			desc = ep3_frankokratia_events.0020.pope_resents
		}
	}
	#triggered loc based on whether Pope endorses crusade
	#triggered loc based on whether they want you to be war leader
	theme = byzantine
	override_background = {
		reference = temple
	}

	left_portrait = {
		character = scope:byz_claimant
		animation = manic
	}
	lower_left_portrait = {
		character = scope:redirecter
	}
	lower_center_portrait = {
		character = scope:pope
	}
	lower_right_portrait = {
		character = scope:byz_emperor
	}

	immediate = {
		title:e_byzantium.holder = {
			save_scope_as = byz_emperor
		}
		faith = {
			religious_head = {
				save_scope_as = pope
			}
			random_faith_ruler = {
				limit = {
					any_owned_story = {
						type = frankokratia_story
					}
				}
				save_scope_as = redirecter
				random_owned_story = {
					type = frankokratia_story
					var:byz_claimant = { save_scope_as = byz_claimant }
					var:financier_title.holder = { save_scope_as = financier }
				}
			}
		}
		save_scope_as = joiner
		add_character_flag = {
			flag = had_event_frankokratia_0020
			years = 5
		}
	}
	#Players receive offer to be war leader - and accept
	option = {
		name = ep3_frankokratia_events.0020.a
		trigger = {
			is_ai = no
			OR = {
				AND = {
					highest_held_title_tier >= tier_duchy
					is_landed = yes
				}
				max_military_strength >= scope:redirecter.max_military_strength
				AND = {
					prestige_level >= 4
					martial > very_high_skill_rating
				}
			}
			scope:redirecter = {
				is_ai = yes
			}
		}
		custom_tooltip = abandon_crusade_tooltip
		custom_tooltip = byz_claimant_crusade_tooltip
		custom_tooltip = may_form_latin_empire_tooltip
		custom_tooltip = crusaders_may_be_paid_tooltip
		add_character_flag = joining_frankokratia
		scope:redirecter = {
			add_character_flag = joining_frankokratia
			random_owned_story = {
				type = frankokratia_story
				make_story_owner = root
				set_variable = {
					name = byz_claimant_champion
					value = root
				}
				every_in_list = {
					variable = frankokratia_leaders
					limit = {
						is_ai = no
					}
					send_interface_message = {
						type = msg_frankokratia_crusader_joining
						title = ep3_frankokratia_crusader_joining
						left_icon = scope:joiner
						desc = frankokratia_crusader_joining_tooltip
					}
				}
				add_to_variable_list = {
 					name = frankokratia_leaders
 					target = root
				}
			}
		}
		set_global_variable = {
			name = byz_claimant_champion
			value = root
		}
		add_character_modifier = {
			modifier = prepared_for_daring_deeds_modifier
			years = 3
		}
		if = {
			limit = {
				scope:byz_claimant = {
					NOR = {
						is_courtier_of = root
						is_ruler = yes
						any_spouse = {
							is_ai = no
							this != root
						}
					}
				}
			}
			add_courtier = scope:byz_claimant
		}
		if = {
			limit = {
				scope:redirecter = {
					has_character_flag = pope_condemned_crusader_claim
				}
			}
			add_piety = medium_piety_loss
			reverse_add_opinion = {
				modifier = angry_opinion
				target = scope:pope
				opinion = -50
			}

		}
		else_if = {
			limit = {
				scope:redirecter = {
					has_character_flag = pope_endorsed_crusader_claim
				}
			}
			add_piety = medium_piety_gain
			reverse_add_opinion = {
				modifier = pleased_opinion
				target = scope:pope
				opinion = 20
			}
		}
		else = {
			reverse_add_opinion = {
				modifier = angry_opinion
				target = scope:pope
				opinion = -30
			}
		}
		if = {
			limit = {
				scope:redirecter = {
					has_character_flag = pope_condemned_crusader_claim
				}
			}
			stress_and_fulfillment_impact = {
				ambitious = medium_stress_impact_loss
				greedy = medium_stress_impact_loss

				zealous = massive_stress_impact_gain
				just = major_stress_impact_gain
				humble = major_stress_impact_gain
				content = major_stress_impact_gain
				craven = major_stress_impact_gain
			}
		}
		else = {
			stress_and_fulfillment_impact = {
				ambitious = medium_stress_impact_loss
				greedy = medium_stress_impact_loss

				just = medium_stress_impact_gain
				humble = medium_stress_impact_gain
				content = medium_stress_impact_gain
				craven = medium_stress_impact_gain
			}
		}
	}

	#Join without becoming war leader
	option = {
		name = ep3_frankokratia_events.0020.b
		add_character_flag = joining_frankokratia
		custom_tooltip = abandon_crusade_tooltip
		custom_tooltip = join_byz_claimant_crusade_tooltip
		custom_tooltip = may_gain_land_latin_empire_tooltip
		custom_tooltip = crusaders_may_be_paid_tooltip
		scope:redirecter = {
			random_owned_story = {
				type = frankokratia_story
				add_to_variable_list = {
 					name = frankokratia_leaders
 					target = root
				}

				save_scope_value_as = {
					name = num_frankokratia_leaders
					value = {
						every_in_list = {
							variable = frankokratia_leaders
							limit = { this != global_var:byz_claimant_champion }
							add = 1
						}

					}
				}

				every_in_list = {
					variable = frankokratia_leaders
					limit = {
						is_ai = no
					}
					send_interface_message = {
						type = msg_frankokratia_crusader_joining
						title = ep3_frankokratia_crusader_joining
						left_icon = scope:joiner
						desc = frankokratia_crusader_joining_tooltip
					}
				}
			}
		}
		if = {
			limit = {
				scope:redirecter = {
					has_character_flag = pope_condemned_crusader_claim
				}
			}
			add_piety = minor_piety_loss
			reverse_add_opinion = {
				modifier = angry_opinion
				target = scope:pope
				opinion = -25
			}

		}
		else_if = {
			limit = {
				scope:redirecter = {
					has_character_flag = pope_endorsed_crusader_claim
				}
			}
			add_piety = medium_piety_gain
		}
		reverse_add_opinion = {
			modifier = angry_opinion
			target = scope:pope
			opinion = -15
		}

		if = {
			limit = {
				scope:redirecter = {
					has_character_flag = pope_condemned_crusader_claim
				}
			}
			stress_and_fulfillment_impact = {
				zealous = major_stress_impact_gain
				just = medium_stress_impact_gain
				humble = minor_stress_impact_gain
				content = medium_stress_impact_gain
			}
		}
		else = {
			stress_and_fulfillment_impact = {
				just = medium_stress_impact_gain
				content = medium_stress_impact_gain
			}
		}
		ai_chance = {
			ai_value_modifier = {
				ai_boldness = 1
				ai_honor = -1
				ai_greed = 1
				ai_rationality = -1
			}
			base = 75
			#Much higher if Pope blessed plan
			modifier = {
				add = 300
				any_claim = {
					tier < tier_empire
					empire = title:e_byzantium
				}
			}
			modifier = {
				add = 100
				opinion = {
					target = scope:redirecter
					value >= 75
				}
			}
			modifier = {
				add = 100
				opinion = {
					target = title:e_byzantium.holder
					value <= -75
				}
			}
			modifier = {
				add = 25
				highest_held_title_tier = tier_county
			}
			#Pope has endorsed crusade
			modifier = {
				add = 150
				scope:redirecter = {
					has_character_flag = pope_endorsed_crusader_claim
				}
				ai_zeal >= low_negative_ai_value
			}
			modifier = {
				factor = 0
				scope:redirecter = {
					has_character_flag = pope_condemned_crusader_claim
				}
				OR = {
					has_trait = diligent
					has_trait = zealous
					has_trait = just
				}
			}
		}
	}
	#Don't join
	option = {
		name = ep3_frankokratia_events.0020.c
		flavor = ep3_frankokratia_events.0020.c.flavor
		if = {
			limit = {
				scope:redirecter = {
					has_character_flag = pope_condemned_crusader_claim
				}
			}
			add_piety = minor_piety_gain
			reverse_add_opinion = {
				modifier = pleased_opinion
				target = scope:pope
				opinion = 15
			}
		}
		else_if = {
			limit = {
				scope:redirecter = {
					NOT = { has_character_flag = pope_endorsed_crusader_claim }
				}
			}
			reverse_add_opinion = {
				modifier = pleased_opinion
				target = scope:pope
				opinion = 15
			}
		}
		reverse_add_opinion = {
			modifier = annoyed_opinion
			target = scope:redirecter
			opinion = -25
		}

		stress_and_fulfillment_impact = {
			greedy = medium_stress_impact_gain
			ambitious = medium_stress_impact_gain
			arbitrary = medium_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			ai_value_modifier = {
				ai_boldness = -1
				ai_honor = 1
				ai_greed = -1
				ai_rationality = 1
			}
			base = 100
			modifier = {
				add = 200
				OR = {
					has_relation_lover = title:e_byzantium.holder
					has_relation_friend = title:e_byzantium.holder
				}
			}
			modifier = {
				add = 200
				any_home_court_hostage = {
					warden = title:e_byzantium.holder
				}
			}
			modifier = {
				add = 100
				has_truce = title:e_byzantium.holder
			}
			modifier = {
				add = 100
				opinion = {
					target = title:e_byzantium.holder
					value >= 75
				}
			}
			modifier = {
				add = 100
				opinion = {
					target = scope:redirecter
					value <= -75
				}
			}
			modifier = {
				add = 200
				highest_held_title_tier = tier_kingdom
			}
			#Make this a little more focused on actual "latins"
			modifier = {
				add = 75
				culture = {
					NOR = {
						has_cultural_pillar = heritage_frankish
						has_cultural_pillar = heritage_latin
					}
				}
			}
			#Pope has condemned crusade
			modifier = {
				add = 200
				scope:redirecter = {
					has_character_flag = pope_condemned_crusader_claim
				}
				ai_zeal >= low_negative_ai_value
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = arbitrary
					has_trait = greedy
					has_trait = fickle
					highest_held_title_tier = tier_empire
				}
			}
		}
	}
}

#On participant death: resave them in the list of frankokratia leaders
ep3_frankokratia_events.0021 = {
	hidden = yes

	trigger = {
		exists = global_var:byz_claimant_champion
		OR = {
			has_character_flag = joining_frankokratia
			global_var:byz_claimant_champion = {
				is_alive = yes
				is_ruler = yes
				any_owned_story = {
					type = frankokratia_story
					is_target_in_variable_list = {
						name = frankokratia_leaders
						target = root
					}
				}
			}
		}
	}

	immediate = {
		#Set them up as joining if crusade hasn't launched yet
		if = {
			limit = {
				has_character_flag = joining_frankokratia
				exists = root.player_heir
				root.player_heir = {
					faith = faith:catholic
				}
			}
			player_heir = { add_character_flag = joining_frankokratia }
		}
		else_if = {
			limit = {
				exists = root.primary_heir
				root.primary_heir = {
					faith = faith:catholic
					highest_held_title_tier <= root.highest_held_title_tier
				}
			}
			primary_heir = { add_character_flag = joining_frankokratia }
		}

		#Add to frankokratia leaders list, if in the list
		if = {
			limit = {
				exists = global_var:byz_claimant_champion
				global_var:byz_claimant_champion = {
					is_alive = yes
					is_ruler = yes
					any_owned_story = {
						type = frankokratia_story
						is_target_in_variable_list = {
							name = frankokratia_leaders
							target = root
						}
					}
				}
			}
			if = {
				limit = {
					exists = root.player_heir
					root.player_heir = {
						faith = faith:catholic
					}
				}
				global_var:byz_claimant_champion = {
					random_owned_story = {
						type = frankokratia_story
						add_to_variable_list = {
							name = frankokratia_leaders
							target = root.player_heir
						}
					}
				}
			}
			else_if = {
				limit = {
					exists = root.primary_heir
					root.primary_heir = {
						faith = faith:catholic
						highest_held_title_tier <= root.highest_held_title_tier
					}
				}
				global_var:byz_claimant_champion = {
					random_owned_story = {
						type = frankokratia_story
						add_to_variable_list = {
							name = frankokratia_leaders
							target = root.primary_heir
						}
					}
				}
			}
		}
	}
}

#The Crusade begins - no wait, the attack on the Greeks does!
ep3_frankokratia_events.0030 = {
	type = character_event
	title = ep3_frankokratia_events.0030.t
	desc = ep3_frankokratia_events.0030.desc

	theme = byzantine
	override_background = {
		trigger = {
			NAND = {
				any_realm_county = {
					OR = {
						empire = title:e_byzantium
						empire = title:e_carpathia
					}
				}
				capital_county = {
					has_coastal_province = yes
				}
			}
		}
		reference = docks
	}
	override_background = {
		trigger = {
			any_realm_county = {
				OR = {
					empire = title:e_byzantium
					empire = title:e_carpathia
				}
			}
			NOT = {
				capital_county = {
					has_coastal_province = yes
				}
			}
		}
		reference = ep3_city_gate
	}
	left_portrait = {
		character = root
		animation = sword_coup_degrace
	}

	right_portrait = {
		character = scope:financier
		animation = marshal
	}

	lower_center_portrait = {
		character = scope:ghw_sponsor
	}
	lower_left_portrait = {
		character = scope:byz_claimant
	}

	lower_right_portrait = {
		character = title:e_byzantium.holder
	}

	immediate = {
		play_music_cue = mx_cue_crusade_starts
		title:e_byzantium.holder = {
			save_scope_as = byz_emperor
		}
		global_var:byz_claimant_champion = {
			save_scope_as = byz_claimant_champion
			random_owned_story = {
				type = frankokratia_story
				var:financier_title.holder ?= { save_scope_as = financier }
				save_scope_as = frankokratia_story
			}
		}
		root.faith.religious_head = {
			save_scope_as = ghw_sponsor
		}
		random_character_war = {
			limit = {
				using_cb = crusading_claim_cb
			}
			save_scope_as = frankokratia_war
		}
		if = {
			limit = {
				is_allied_to = scope:byz_emperor
			}
			break_alliance = scope:byz_emperor
		}
		#Show tooltip that you declared war
		custom_tooltip = frankokratia_war_begins_tooltip
		if = {
			limit = {
				this != scope:byz_claimant_champion
			}
			custom_tooltip = frankokratia_war_join_tooltip
		}
		#financier modifier gain
		add_character_modifier = {
			modifier = grand_crusader_fleet_modifier
			years = 3
		}
	}

	option = {
		name = ep3_frankokratia_events.0030.a
		stress_and_fulfillment_impact = {
			brave = minor_stress_impact_loss
			ambitious = minor_stress_impact_loss
			zealous = miniscule_stress_impact_loss
		}
	}
}

#Inform all other rulers of involved religions
ep3_frankokratia_events.0031 = {
	type = character_event
	title = ep3_frankokratia_events.0031.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					OR = {
						liege = title:e_byzantium.holder
						this = title:e_byzantium.holder
					}
				}
				desc = ep3_frankokratia_events.0031.desc_byz
			}
			triggered_desc = {
				trigger = {
					OR = {
						faith = faith:catholic
						faith = {
							religion = religion:christianity_religion
							faith_hostility_level = {
 								target = faith:catholic
 								value < faith_hostile_level
 							}
						}
					}
				}
				desc = ep3_frankokratia_events.0031.desc_catholic
			}
			desc = ep3_frankokratia_events.0031.desc_target
		}
	}
	#Desc for target faith of crusade
	#Desc for Catholics
	#Desc for Byzantines - first hearing of crusade
	theme = byzantine
	override_background = {
		reference = docks
	}

	left_portrait = {
		character = scope:byz_claimant_champion
		animation = sword_coup_degrace
		camera = camera_event_left_forward
	}
	right_portrait = {
		character = scope:byz_claimant
		triggered_animation = {
			trigger = { religion = religion:christianity_religion }
			animation = acknowledging # anim uses crucifix scepter
		}
		animation = war_over_tie
		camera = camera_event_right_forward
	}
	lower_right_portrait = {
		character = scope:byz_emperor
	}
	lower_left_portrait = {
		character = scope:financier
	}
	immediate = {
		global_var:byz_claimant_champion = {
			save_scope_as = byz_claimant_champion
			random_owned_story = {
				type = frankokratia_story
				var:financier_title.holder = {
					save_scope_as = financier
				}
				var:byz_claimant = {
					save_scope_as = byz_claimant
				}
			}
		}
		faith:catholic = {
			religious_head = {
				save_scope_as = pope
			}
		}
		title:e_byzantium.holder = {
			save_scope_as = byz_emperor
		}
		scope:byz_claimant_champion = {
			add_character_flag = need_military_outfit
		}
		custom_tooltip = abandoned_crusade_general_tooltip
		show_as_tooltip = {
			scope:byz_claimant_champion = {
				start_war = {
					casus_belli = crusading_claim_cb
					target = title:e_byzantium.holder
					claimant = scope:byz_claimant
					target_title = title:e_byzantium
				}
			}
		}
	}
	option = {
		name = ep3_frankokratia_events.0031.a
	}
	after = {
		scope:byz_claimant_champion = {
			remove_character_flag = need_military_outfit
		}
	}
}

#Emperor tries to pay latins
ep3_frankokratia_events.0040 = {
	hidden = yes

	trigger = {
		NOT = { has_character_flag = had_frankokratia_events_0040 }
	}

	immediate = {
		random_ruler = {
			limit = {
				any_owned_story = {
					type = frankokratia_story
				}
			}
			save_scope_as = byz_claimant_champion
			random_owned_story = {
				type = frankokratia_story
				var:financier_title.holder ?= { save_scope_as = financier }
				save_scope_as = frankokratia_story
			}
		}
		#Previous emperor needs to take the treasury
		scope:claimant = {
			pay_treasury_or_gold = {
				target = scope:defender
				value = 325
			}
		}
		title:e_byzantium.holder = { ep3_frankokratia_save_financier_sate_lands_effect = yes }
		add_character_flag = {
			flag = had_frankokratia_events_0040
			years = 1
		}
		#Save regiments to give up
		if = {
			limit = {
				any_maa_regiment = {
					is_title_maa_regiment = yes
					is_maa_type = cataphract
				}
			}
			random_maa_regiment = {
				limit = {
					is_title_maa_regiment = yes
					is_maa_type = cataphract
				}
				save_scope_as = regiment_1
			}
		}
		else_if = {
			limit = {
				any_maa_regiment = {
					is_title_maa_regiment = yes
					this != scope:regiment_1
					NOT = { is_maa_type = varangian_guards }
				}
			}
			random_maa_regiment = {
				limit = {
					is_title_maa_regiment = yes
					this != scope:regiment_1
					NOT = { is_maa_type = varangian_guards }
				}
				save_scope_as = regiment_2
			}
		}
		if = {
			limit = {
				any_maa_regiment = {
					is_title_maa_regiment = yes
					is_maa_type = cataphract
					this != scope:regiment_1
				}
			}
			random_maa_regiment = {
				limit = {
					is_title_maa_regiment = yes
					this != scope:regiment_1
					is_maa_type = cataphract
				}
				save_scope_as = regiment_2
			}
		}
		else_if = {
			limit = {
				any_maa_regiment = {
					is_title_maa_regiment = yes
					this != scope:regiment_1
					NOT = { is_maa_type = varangian_guards }
				}
			}
			random_maa_regiment = {
				limit = {
					is_title_maa_regiment = yes
					this != scope:regiment_1
					NOT = { is_maa_type = varangian_guards }
				}
				save_scope_as = regiment_2
			}
		}
	}
	#PAY THEM BY ANY MEANS NECESSARY
	option = {
		show_as_tooltip = {
			ep3_frankokratia_paying_off_latins_effect = yes
		}

		scope:attacker = {
			trigger_event = ep3_frankokratia_events.0041
		}
		add_character_flag = paying_off_latins
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = -1
				ai_rationality = -1
				ai_honor = 1
			}
			modifier = {
				add = -75
				gold < major_gold_value
			}
			modifier = {
				add = -25
				gold < medium_gold_value
			}
			modifier = {
				add = -50
				scope:attacker = {
					dread >= 50
				}
			}
			modifier = {
				add = -50
				scope:attacker = {
					dread >= 75
				}
			}
			modifier = {
				add = -25
				scope:attacker = {
					dread >= 25
				}
			}
			modifier = {
				add = -100
				is_at_war = yes
			}
		}
	}
	#There simply ISN'T any money
	option = {
		show_as_tooltip = {
			pay_treasury_or_gold = {
				target = scope:attacker
				value = minor_treasury_or_gold_value
			}
			pay_treasury_or_gold = {
				target = scope:financier
				value = minor_treasury_or_gold_value
			}
		}
		scope:attacker = {
			trigger_event = ep3_frankokratia_events.0041
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 1
				ai_rationality = 1
				ai_honor = -1
			}
		}
	}
}

#Representative of the latins meets emperor after victory, expecting reward
ep3_frankokratia_events.0041 = {
	type = character_event
	title = ep3_frankokratia_events.0041.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:claimant.capital_county = {
						this = title:c_byzantion
					}
				}
				desc = ep3_frankokratia_events.0041.intro_constantinople
			}
			desc = ep3_frankokratia_events.0041.intro_generic
		}
		desc = ep3_frankokratia_events.0041.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					scope:claimant = {
						has_character_flag = paying_off_latins
					}
				}
				desc = ep3_frankokratia_events.0041.trying_to_pay
			}
			desc = ep3_frankokratia_events.0041.not_trying_to_pay
		}
	}

	theme = byzantine

	override_background = {
		reference = ep3_byzantium_throneroom
	}
	left_portrait = {
		character = root
		animation = war_over_win
	}

	right_portrait = {
		character = scope:claimant
		animation = bribing
	}

	lower_left_portrait = {
		character = scope:financier
	}
	lower_right_portrait = {
		character = scope:defender
	}

	trigger = {
		#All the emperor's vassals have been through the pre-collapse event
		trigger_if = {
			limit = {
				#The Byz vassals get like 40 days, and then this event is being fired no matter what
				scope:frankokratia_story = {
					OR = {
						NOT = {
    						exists = var:franko_conclusion_counter
    					}
    					var:franko_conclusion_counter < 20
					}
				}
			}
			title:e_byzantium.holder = {
				NOT = {
					any_vassal_or_below = {
						is_ai = no
						NOT = {
							has_character_flag = byz_aftermath_fate
						}
					}
				}
			}
		}
	}
	 on_trigger_fail = {
    	#Count how many times we've tried firing this event, in order to eventually force-fire
    	if = {
    		limit = {
    			scope:frankokratia_story = {
    				NOT = {
    					has_variable = franko_conclusion_counter
    				}
    			}
    		}
    		scope:frankokratia_story = {
    			set_variable = {
    				name = franko_conclusion_counter
    				value = 1
    			}
    		}
    	}
    	else = {
    		scope:frankokratia_story = {
    			change_variable = {
    				name = franko_conclusion_counter
    				add = 1
    			}
    		}
    	}
    	if = {
    		limit = {
    			scope:frankokratia_story = {
    				has_variable = franko_conclusion_counter
    				var:franko_conclusion_counter < 25
    			}
    		}
    		trigger_event = {
    			id = ep3_frankokratia_events.0041
    			days = 2
    		}
    	}
    }

	immediate = {
		add_character_flag = need_military_outfit
		#Get those dead guys and nobodies and heathens outta here
		scope:frankokratia_story = {
			#Non Christian allies should get some marginal goodies
			if = {
				limit = {
					any_in_list = {
						variable = frankokratia_leaders
						is_alive = yes
						is_ruler = yes
						NOT = {
							faith.religion = religion:christianity_religion
						}
					}
				}
				every_in_list = {
					variable = frankokratia_leaders
					limit = {
						is_alive = yes
						is_ruler = yes
						NOT = {
							faith.religion = religion:christianity_religion
						}
					}
					add_to_list = non_christian_franko_leaders
				}
			}
			if = {
				limit = {
					any_in_list = {
						variable = frankokratia_leaders
						OR = {
							is_alive = no
							is_ruler = no
							NOT = {
								faith.religion = religion:christianity_religion
							}
						}
					}
				}
				while = {
					limit = {
						any_in_list = {
							variable = frankokratia_leaders
							OR = {
								is_alive = no
								is_ruler = no
								NOT = {
									faith.religion = religion:christianity_religion
								}
							}
						}
					}
					random_in_list = {
						variable = frankokratia_leaders
						limit = {
							OR = {
								is_alive = no
								is_ruler = no
								NOT = {
									faith.religion = religion:christianity_religion
								}
							}
						}
						save_scope_as = gone_leader
					}
					remove_list_variable = {
						name = frankokratia_leaders
						target = scope:gone_leader
					}
				}
			}
		}

		#Set up the wealth transfer
		if = {
			limit = {
				scope:claimant = {
					has_character_flag = paying_off_latins
				}
			}
			ep3_frankokratia_gather_governor_funds_effect = yes
		}
		#Need to know what titles will become latin empire
		hidden_effect_new_object = {
			ep3_frankokratia_designate_latin_empire_effect = yes
			ep3_latin_empire_designate_financier_lands_effect = yes
		}
		save_scope_value_as = {
			name = ep3_sacking_byz_capital_payoff_value
			value = ep3_sacking_byz_capital_payoff_value
		}
	}

	#We are taking this city to get what we deserve
	option = {
		name = ep3_frankokratia_events.0041.a
		flavor = ep3_frankokratia_events.0041.a.flavor

		ep3_frankokratia_capital_sacking_effect = yes
		custom_tooltip = frankokratia_latin_emp_army_tooltip

		#Stress if choice is between sacking or not being paid
		if = {
			limit = {
				scope:claimant = {
					NOT = { has_character_flag = paying_off_latins }
				}
			}
			stress_and_fulfillment_impact = {
				compassionate = major_stress_impact_gain
				forgiving = major_stress_impact_gain
				content = major_stress_impact_gain
			}
		}
		#Stress if you could choose payment
		else = {
			stress_and_fulfillment_impact = {
				compassionate = massive_stress_impact_gain
				forgiving = massive_stress_impact_gain
				zealous = medium_stress_impact_gain
				content = massive_stress_impact_gain
			}
		}

		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_compassion = -1
				ai_vengefulness = 1
				ai_greed = 1
				ai_rationality = -1
				ai_boldness = 1
			}
			modifier = {
				culture = {
					NOR = {
						has_cultural_pillar = heritage_frankish
						has_cultural_pillar = heritage_latin
						has_cultural_pillar = heritage_west_germanic
						has_cultural_pillar = heritage_central_germanic
					}
				}
				add = -50
			}
			modifier = {
				NOT = {
					faith = faith:catholic
				}
				add = -100
			}
			modifier = {
				highest_held_title_tier >= tier_empire
				add = -100
			}
			modifier = {
				highest_held_title_tier >= tier_kingdom
				add = -50
			}
			modifier = {
				highest_held_title_tier = tier_county
				add = 50
			}
			modifier = {
				add = -50
				scope:claimant = {
					has_character_flag = paying_off_latins
				}
			}
			modifier = {
				factor = 0
				has_trait = forgiving
			}
			modifier = {
				factor = 0
				scope:claimant = {
					has_character_flag = paying_off_latins
				}
				OR = {
					has_trait = compassionate
					has_trait = content
				}
			}
		}
	}

	#Even without being paid... I'll try to send the men home
	option = {
		name = ep3_frankokratia_events.0041.b
		flavor = ep3_frankokratia_events.0041.b.flavor
		trigger = {
			scope:claimant = {
				NOT = { has_character_flag = paying_off_latins }
			}
		}
		duel = {
			skills = { diplomacy martial }
			value = medium_skill_rating
			30 = { #The crusaders head home
				desc = ep3_frankokratia_events.0041.b_success
				compare_modifier = {
					value = scope:duel_value
					multiplier = 3.5
					min = -29
				}
				modifier = {
					scope:claimant = {
						has_character_flag = paying_off_latins
					}
					add = 100
				}
				modifier = {
					highest_held_title_tier >= tier_kingdom
					add = 20
				}
				modifier = {
					dread >= 75
					add = 20
				}

				send_interface_toast = {
					title = ep3_frankokratia_events.0041.b_success
					type = event_toast_effect_good
					left_icon = root
					right_icon = scope:claimant

					if = {
						limit = {
							has_lifestyle = martial_lifestyle
						}
						add_martial_lifestyle_perk_points = 3
					}
					else_if = {
						limit = {
							has_lifestyle = diplomacy_lifestyle
						}
						add_diplomacy_lifestyle_perk_points = 3
					}
					else = {
						add_diplomacy_lifestyle_perk_points = 2
						add_martial_lifestyle_perk_points = 1
					}
					if = {
						limit = {
							scope:claimant = {
								has_character_flag = swore_to_convert_byz_catholic
							}
						}
						add_piety = massive_piety_gain
					}
					else = {
						add_piety = major_piety_gain
					}
					set_nickname_effect = { NICKNAME = nick_protosebastos }

					scope:claimant = {
						pay_short_term_gold = {
							target = scope:attacker
							gold = minor_gold_value
						}
						pay_short_term_gold = {
							target = scope:financier
							gold = minor_gold_value
						}
					}
					hidden_effect = {
						#Every player gets walk-away flavor event
						scope:frankokratia_story = {
							every_in_list = {
								variable = frankokratia_leaders
								trigger_event = {
									id = ep3_frankokratia_events.0045
									days = 1
								}
								add_character_flag = dont_send_general_event_franko
							}
						}
					}
					add_character_flag = ep3_frankokratia_events.0041_succeeded_duel
				}
				#Non-crusader players get flavor event
				every_player = {
					limit = {
						ep3_frankokratia_notification_recipient_trigger = yes
					}
					add_character_flag = frankokratia_crusaders_leave_unpaid_outcome
					trigger_event = {
						id = ep3_frankokratia_events.0060
						days = 1
					}
				}
				#Force end on story owner to be safe (necessary for AI owner)
				if = {
					limit = {
						global_var:byz_claimant_champion ?= {
							any_owned_story = {
								type = frankokratia_story
							}
						}
					}
					global_var:byz_claimant_champion = {
						trigger_event = {
							id = ep3_frankokratia_events.0061
							days = 3
						}
					}
				}
			}
			70 = { #The latins ignore you and sack Constantinople
				desc = ep3_frankokratia_events.0041.b_failure
				compare_modifier = {
					value = scope:duel_value
					multiplier = -3.5
					min = -69
				}
				modifier = {
					highest_held_title_tier <= tier_county
					add = 20
				}
				modifier = {
					dread <= 20
					add = 20
				}
				send_interface_toast = {
					title = ep3_frankokratia_events.0041.b_failure
					type = event_toast_effect_bad
					left_icon = root
					right_icon = scope:claimant

					add_stress = massive_stress_impact_gain
					custom_tooltip = ep3_frankokratia.0041_effects_from_a_tooltip
					hidden_effect = {
						ep3_frankokratia_capital_sacking_effect = yes
					}
				}
			}
		}
		stress_and_fulfillment_impact = {
			greedy = major_stress_impact_gain
			ambitious = major_stress_impact_gain
			sadistic = major_stress_impact_gain
			vengeful = massive_stress_impact_gain
			wrathful = major_stress_impact_gain
			arrogant = major_stress_impact_gain
		}
		ai_chance = {
			base = 0
			ai_value_modifier = {
				ai_compassion = 1
				ai_vengefulness = -1
				ai_greed = -1
				ai_rationality = 1
				ai_boldness = -1
			}
			modifier = {
				add = 50
				OR = {
					has_trait = compassionate
					has_trait = forgiving
				}
			}
			modifier = {
				add = -50
				OR = {
					has_trait = callous
					has_trait = honest
				}
			}
			modifier = {
				add = -25
				highest_held_title_tier <= tier_county
			}
			modifier = {
				add = -25
				dread < 20
			}
			modifier = {
				add = -50
				NOR = {
					martial >= extremely_high_skill_rating
					diplomacy >= extremely_high_skill_rating
					AND = {
						martial > high_skill_rating
						diplomacy > high_skill_rating
					}
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = sadistic
					has_trait = ambitious
					has_trait = vengeful
					has_trait = wrathful
					has_trait = sadistic
					diplomacy <= low_skill_rating
					martial <= low_skill_rating
				}
			}
		}
	}

	#I suppose this payment will do...
	option = {
		name = ep3_frankokratia_events.0041.c
		flavor = ep3_frankokratia_events.0041.c.flavor
		trigger = {
			scope:claimant = {
				has_character_flag = paying_off_latins
			}
		}
		set_nickname_effect = { NICKNAME = nick_protosebastos }
		scope:claimant = {
			ep3_frankokratia_paying_off_latins_effect = yes
		}
		#Every player gets walk-away flavor event
		scope:frankokratia_story = {
			every_in_list = {
				variable = frankokratia_leaders
				limit = {
					is_ai = no
				}
				add_character_flag = dont_send_general_event_franko
				trigger_event = {
					id = ep3_frankokratia_events.0045
					days = 1
				}
			}
		}
		#Non-crusader players get flavor event
		every_player = {
			limit = {
				ep3_frankokratia_notification_recipient_trigger = yes
			}
			add_character_flag = frankokratia_crusaders_paid_outcome
			trigger_event = {
				id = ep3_frankokratia_events.0060
				days = 1
			}
		}
		#Force end on story owner to be safe (necessary for AI owner)
		if = {
			limit = {
				global_var:byz_claimant_champion ?= {
					any_owned_story = {
						type = frankokratia_story
					}
				}
			}
			global_var:byz_claimant_champion = {
				trigger_event = {
					id = ep3_frankokratia_events.0061
					days = 3
				}
			}
		}
		stress_and_fulfillment_impact = {
			greedy = major_stress_impact_gain
			ambitious = major_stress_impact_gain
			vengeful = major_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_compassion = 1
				ai_vengefulness = -1
				ai_greed = -1
				ai_rationality = 1
				ai_boldness = -1
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = ambitious
					has_trait = vengeful
				}
			}
		}
	}

	after = {
		every_player = {
			limit = {
				has_character_flag = dont_send_general_event_franko
			}
			remove_character_flag = dont_send_general_event_franko
		}
		if = {
			limit = {
				scope:claimant = {
					has_character_flag = paying_off_latins
				}
			}
			scope:claimant = {
				remove_character_flag = paying_off_latins
			}
		}
		if = {
			limit = {
				scope:claimant = {
					has_character_modifier = bent_before_crusaders_modifier
				}
			}
			remove_character_flag = need_military_outfit
		}
		if = {
			limit = {
				has_character_flag = ep3_frankokratia_events.0041_succeeded_duel
			}
			remove_character_flag = need_military_outfit
			remove_character_flag = ep3_frankokratia_events.0041_succeeded_duel
		}
	}
}

#Constantinople is sacked and new Latin empire is chosen
ep3_frankokratia_events.0042 = {
	type = character_event
	title = ep3_frankokratia_events.0042.t
	desc = {
		desc = ep3_frankokratia_events.0042.desc
		triggered_desc = {
			trigger = {
				title:e_byzantium.holder.capital_county = { this = title:c_byzantion }
			}
			desc = ep3_frankokratia_events.0042.constantinople
		}
		desc = ep3_frankokratia_events.0042.desc_outro
	}

	theme = byzantine
	window = visit_settlement_window
	override_background = {
		trigger = {
			title:e_byzantium.holder.capital_county = { this = title:c_byzantion }
		}
		reference = ep3_constantinople_riot
	}
	override_background = {
		trigger = {
			NOT = { title:e_byzantium.holder.capital_county = { this = title:c_byzantion } }
		}
		reference = burning_building
	}

	widget = {
		gui = "event_window_widget_vfx_conclusion_smoke"
		container = "background_shader_vfx_container"
	}
	left_portrait = {
		character = root
		animation = celebrate_sword
		camera = camera_event_left_forward
	}

	right_portrait = {
		character = scope:financier
		animation = scheme
		camera = camera_event_right
	}

	lower_left_portrait = {
		character = scope:emp_beneficiary_2
	}
	lower_center_portrait = {
		character = scope:emp_beneficiary
	}

	immediate = {
		play_music_cue = "mx_cue_combat_2"
		add_character_flag = need_military_outfit
		#Save beneficiaries
		hidden_effect_new_object = {
			ep3_frankokratia_pick_emperor_beneficiary_effect = yes
		}
		ep3_frankokratia_kill_byzantines_effect = yes
		if = {
			limit = {
				#Let them keep their titles if it creates a contiguous empire with the new latin kingdoms
				ep3_frankokratia_discard_old_lands_trigger = yes
			}
			#Save root's old titles to give away
			every_held_title = {
				limit = {
					NOT = {
						tier = tier_barony
					}
					NOR = {
						this = scope:latin_capital.kingdom
						kingdom = scope:latin_capital.kingdom
						AND = {
							exists = scope:latin_kingdom_2
							kingdom = scope:latin_kingdom_2
						}
						AND = {
							exists = scope:latin_kingdom_2
							this = scope:latin_kingdom_2
						}
					}
				}
				add_to_list = root_old_titles
			}
			every_vassal = {
				limit = {
					primary_title = {
						NOR = {
							this = scope:latin_capital.kingdom
							kingdom = scope:latin_capital.kingdom
							AND = {
								exists = scope:latin_kingdom_2
								kingdom = scope:latin_kingdom_2
							}
							AND = {
								exists = scope:latin_kingdom_2
								this = scope:latin_kingdom_2
							}
						}
					}
				}
				add_to_list = root_old_vassals
			}
			if = {
				limit = {
					top_liege != this
				}
				set_variable = {
					name = old_liege
					value = liege
				}
			}
		}

		random_owned_story = {
			type = frankokratia_story
			save_scope_as = frankokratia_story
		}

		#Save player crusaders in order of strength
		if = {
			limit = {
				scope:frankokratia_story = {
					any_in_list = {
						variable = frankokratia_leaders
						is_ai = no
						this != root
						has_character_flag = frankokratia_sufficient_warscore
					}
				}
			}
			scope:frankokratia_story = {
				ordered_in_list = {
					variable = frankokratia_leaders
					order_by = max_military_strength
					limit = {
						is_ai = no
						this != root
						has_character_flag = frankokratia_sufficient_warscore
					}
					save_scope_as = player_1
				}
			}
		}
		if = {
			limit = {
				exists = scope:player_1
				scope:frankokratia_story = {
					any_in_list = {
						variable = frankokratia_leaders
						is_ai = no
						NOR = {
							this = root
							this = scope:player_1
						}
						has_character_flag = frankokratia_sufficient_warscore
					}
				}
			}
			scope:frankokratia_story = {
				ordered_in_list = {
					variable = frankokratia_leaders
					order_by = max_military_strength
					limit = {
						is_ai = no
						NOR = {
							this = root
							this = scope:player_1
						}
						has_character_flag = frankokratia_sufficient_warscore
					}
					save_scope_as = player_2
				}
			}
		}
		add_to_list = designated_for_latin_emp_titles
		scope:financier = { add_to_list = designated_for_latin_emp_titles }
		scope:frankokratia_story = {
			every_in_list = {
				variable = frankokratia_leaders
				create_character_memory = {
					type = sacked_byzantium_memory
				}
			}
		}
	}

	#I SHALL BE LATIN EMPEROR
	option = {
		name = ep3_frankokratia_events.0042.a
		save_scope_as = latin_emperor
		save_scope_as = latin_empire_receiver
		#Character flag to track when all latin emp titles are distributed
		add_to_list = gained_latin_emp_titles
		ep3_frankokratia_grant_latin_empire_effect = yes
		ep3_frankokratia_clear_old_lands_change_capital_effect = yes
		stress_and_fulfillment_impact = {
			arrogant = minor_stress_impact_loss
			zealous = minor_stress_impact_loss
			humble = medium_stress_impact_gain
			content = medium_stress_impact_gain
			lazy = minor_stress_impact_gain
			paranoid = minor_stress_impact_gain
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_boldness = 1
				ai_greed = 1
				ai_energy = 1
			}
			modifier = {
				add = 25
				OR = {
					has_trait = arrogant
					has_trait = zealous
				}
			}
			modifier = {
				add = -50
				highest_held_title_tier = tier_kingdom
			}
			modifier = {
				factor = 0
				OR = {
					AND = {
						scope:player_1 ?= {
							has_character_flag = frankokratia_high_warscore
						}
					}
					AND = {
						scope:player_2 ?= {
							has_character_flag = frankokratia_high_warscore
						}
					}
					highest_held_title_tier >= tier_empire
				}
			}
		}
	}

	#Give to player #1
	option = {
		name = ep3_frankokratia_events.0042.b
		trigger = {
			exists = scope:player_1
		}
		scope:player_1 = { save_scope_as = latin_empire_receiver }

		add_character_flag = franko_granting_to_player
		scope:player_1 = { trigger_event = ep3_frankokratia_events.0044 }
		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_loss
			ambitious = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				exists = scope:player_2
				scope:player_2 = {
					has_character_flag = frankokratia_high_warscore
				}
				NOT = {
					scope:player_1 = {
						has_character_flag = frankokratia_high_warscore
					}
				}
			}
		}
	}
	#Give to player #2
	option = {
		name = ep3_frankokratia_events.0042.c
		trigger = {
			exists = scope:player_2
		}
		scope:player_2 = { save_scope_as = latin_empire_receiver }
		add_character_flag = franko_granting_to_player
		scope:player_2 = { trigger_event = ep3_frankokratia_events.0044 }
		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_loss
			ambitious = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				scope:player_2 = {
					has_character_flag = frankokratia_high_warscore
				}
				NOT = {
					scope:player_1 = {
						has_character_flag = frankokratia_high_warscore
					}
				}
			}
		}
	}
	#Financier should be latin emperor
	option = {
		name = ep3_frankokratia_events.0042.d
		trigger = {
			NOT = { exists = scope:player_1 }
		}
		scope:financier = {
			save_scope_as = latin_emperor
			save_scope_as = latin_empire_receiver
		}
		scope:latin_emperor = {
			add_trait = despoiler_of_byzantium
		}

		ep3_frankokratia_grant_latin_empire_effect = yes
		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_loss
			just = minor_stress_impact_loss
			paranoid = minor_stress_impact_gain
			ambitious = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
		}
		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_greed = -1
				ai_honor = 1
				ai_boldness = -1
			}
			modifier = {
				add = 25
				OR = {
					has_trait = trusting
					has_trait = just
					has_trait = arrogant
				}
			}
			modifier = {
				add = -25
				has_trait = paranoid
			}
			modifier = {
				factor = 0
				OR = {
					AND = {
						exists = scope:player_1
						scope:player_1 = {
							has_character_flag = frankokratia_high_warscore
						}
					}
					AND = {
						exists = scope:player_2
						scope:player_2 = {
							has_character_flag = frankokratia_high_warscore
						}
					}
				}
			}
		}
	}
	option = {
		name = ep3_frankokratia_events.0042.e
		trigger = {
			NOT = { exists = scope:player_2 }
			exists = scope:emp_beneficiary_3
			is_ai = no
		}
		save_scope_as = latin_empire_receiver
		#Character flag to track when all latin emp titles are distributed
		add_to_list = gained_latin_emp_titles
		scope:emp_beneficiary_3 = { save_scope_as = latin_emperor }
		scope:latin_emperor = {
			add_trait = despoiler_of_byzantium
		}
		ep3_frankokratia_grant_latin_empire_effect = yes
		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_loss
			ambitious = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
	}
	option = {
		name = ep3_frankokratia_events.0042.f
		trigger = {
			exists = scope:emp_beneficiary_2
			is_ai = no
		}
		save_scope_as = latin_empire_receiver
		#Character flag to track when all latin emp titles are distributed
		add_to_list = gained_latin_emp_titles
		scope:emp_beneficiary_2 = { save_scope_as = latin_emperor }
		scope:latin_emperor = {
			add_trait = despoiler_of_byzantium
		}
		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_loss
			ambitious = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ep3_frankokratia_grant_latin_empire_effect = yes
	}
	option = {
		name = ep3_frankokratia_events.0042.g
		save_scope_as = latin_empire_receiver
		#Character flag to track when all latin emp titles are distributed
		add_to_list = gained_latin_emp_titles
		scope:emp_beneficiary = { save_scope_as = latin_emperor }
		scope:latin_emperor = {
			add_trait = despoiler_of_byzantium
		}
		ep3_frankokratia_grant_latin_empire_effect = yes
		stress_and_fulfillment_impact = {
			trusting = minor_stress_impact_loss
			ambitious = minor_stress_impact_gain
			greedy = minor_stress_impact_gain
			arrogant = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = -1
			}
			modifier = {
				add = 25
				has_trait = trusting
			}
			modifier = {
				factor = 0
				OR = {
					AND = {
						exists = scope:player_1
						scope:player_1 = {
							has_character_flag = frankokratia_high_warscore
						}
					}
					AND = {
						exists = scope:player_2
						scope:player_2 = {
							has_character_flag = frankokratia_high_warscore
						}
					}
				}
			}
		}
	}

	after = {
		remove_character_flag = need_military_outfit
		#trigger hidden event that distributes lands when latin emp is chosen
		if = {
			limit = {
				NOT = { has_character_flag = franko_granting_to_player }
			}
			trigger_event = ep3_frankokratia_events.0043
		}
		else = {
			remove_character_flag = franko_granting_to_player
		}
	}
}

#Hidden event that designates gained Latin lands and fires land gain events
ep3_frankokratia_events.0043 = {
	hidden = yes

	immediate = {
		scope:financier = {
			ep3_latin_empire_grant_financier_lands_effect = yes
		}
		ep3_frankokratia_distribute_lands_to_crusaders_effect = yes

		#If latin emperor only has one county, just shatter byzantine empire
		if = {
			limit = {
				exists = scope:latin_emperor
				scope:latin_emperor = {
					NOT = {
						any_realm_county = {
							this != scope:latin_emperor.capital_county
						}
					}
				}
			}
			#Shatter byzantium event
			title:e_byzantium.holder = {
				trigger_event = {
					id = ep3_frankokratia_events.0050
					days = 1
				}
			}
		}
		#Otherwise, start distributing counties to latin lords
		else = {
			scope:frankokratia_story = {
				random_in_list = {
					variable = frankokratia_leaders
					limit = {
						NOR = {
							this = scope:latin_empire_receiver
							this = scope:financier
						}
						has_variable = latin_county
					}
					trigger_event = ep3_frankokratia_events.0044
				}
			}
		}
	}
}

#Sacking and land gain event for non-story owner attackers
ep3_frankokratia_events.0044 = {
	type = character_event
	title = ep3_frankokratia_events.0044.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					any_owned_story = {
						type = frankokratia_story
					}
				}
				desc = ep3_frankokratia_events.0044.desc_past_tense
			}
			desc = ep3_frankokratia_events.0044.desc
		}
		first_valid = {
			triggered_desc = {
				trigger = {
					this = scope:latin_empire_receiver
				}
				desc = ep3_frankokratia_events.0044.outro_emperor
			}
			desc = ep3_frankokratia_events.0044.outro_lord
		}
	}

	theme = byzantine
	override_background = {
		trigger = {
			scope:latin_byz_capital_barony = { this = title:b_constantinople }
		}
		reference = ep3_constantinople_riot
	}
	override_background = {
		trigger = {
			NOT = { scope:latin_byz_capital_barony = { this = title:b_constantinople } }
		}
		reference = burning_building
	}
	override_effect_2d = {
		reference = smoke
	}
	left_portrait = {
		character = root
		animation = random_weapon_celebrate
	}

	lower_center_portrait = {
		character = scope:beneficiary_3
	}
	lower_right_portrait = {
		character = scope:beneficiary_2
	}
	lower_left_portrait = {
		character = scope:beneficiary
	}

	trigger = {
	}

	immediate = {
		add_dread = major_dread_gain
		#Clear last character's list entries
		if = {
			limit = {
				any_in_list = {
					list = root_old_titles
					count >= 1
				}
			}
			every_in_list = {
				list = root_old_titles
				remove_from_list = root_old_titles
			}
		}
		if = {
			limit = {
				any_in_list = {
					list = root_old_vassals
					count >= 1
				}
			}
			every_in_list = {
				list = root_old_vassals
				remove_from_list = root_old_vassals
			}
		}
		if = {
			limit = {
				this = scope:latin_empire_receiver
			}
			scope:claimant.capital_barony = {
				save_scope_as = latin_byz_capital_barony
			}
		}
		else = {
			scope:latin_emperor.capital_barony = {
				save_scope_as = latin_byz_capital_barony
			}
		}
		add_character_flag = need_military_outfit
		#Get latin emperor as second character?
		if = {
			limit = {
				this = scope:latin_empire_receiver
			}
			if = {
				limit = {
					NOT = {
						culture = {
							NOR = {
								this = scope:claimant.capital_county.culture
								this = scope:attacker.culture
								this = scope:financier.culture
							}
						}
					}
				}
				culture = {
					change_cultural_acceptance = {
						target = scope:claimant.capital_county.culture
						value = massive_cultural_acceptance_loss
						desc = sacked_imperial_capital_cultural_acceptance
					}
				}
			}
			hidden_effect_new_object = {
			 	ep3_frankokratia_pick_emperor_beneficiary_effect = yes
				var:emp_beneficiary = {
					save_scope_as = beneficiary
				}
				if = {
					limit = {
						has_variable = emp_beneficiary_2
					}
					var:emp_beneficiary_2 = {
						save_scope_as = beneficiary_2
					}
				}
				if = {
					limit = {
						has_variable = emp_beneficiary_3
					}
					var:emp_beneficiary_3 = {
						save_scope_as = beneficiary_3
					}
				}
				scope:claimant.capital_county = {
					custom_tooltip = byz_capital_building_destroyed_past_tooltip
					custom_tooltip = franko_county_control_past_tooltip
					custom_tooltip = franko_development_past_tooltip
				}
			}
		}
		else = {
			save_scope_as = latin_title_gainer
			hidden_effect_new_object = {
				#Save beneficiaries
				ep3_frankokratia_pick_crusader_beneficiary_effect = yes
				#Save beneficiary variables on character as scopes
				var:beneficiary = {
					save_scope_as = beneficiary
				}
				if = {
					limit = {
						has_variable = beneficiary_2
					}
					var:beneficiary_2 = { save_scope_as = beneficiary_2 }
				}
				if = {
					limit = {
						has_variable = beneficiary_3
					}
					var:beneficiary_3 = { save_scope_as = beneficiary_3 }
				}
			}
			scope:latin_emperor.capital_county = {
				custom_tooltip = byz_capital_building_destroyed_past_tooltip
				custom_tooltip = franko_county_control_past_tooltip
				custom_tooltip = franko_development_past_tooltip
			}
		}
		if = {
			limit = {
				#Let them keep their titles if it creates a contiguous empire with the new latin kingdoms
				ep3_frankokratia_discard_old_lands_trigger = yes
			}
			#Save root's old titles to give away
			every_held_title = {
				limit = {
					NOR = {
						tier = tier_barony
						tier >= tier_empire
					}
					NOR = {
						this = scope:latin_capital.kingdom
						kingdom = scope:latin_capital.kingdom
						AND = {
							exists = scope:latin_kingdom_2
							kingdom = scope:latin_kingdom_2
						}
						AND = {
							exists = scope:latin_kingdom_2
							this = scope:latin_kingdom_2
						}
					}
				}
				add_to_list = root_old_titles
			}
			every_held_title = {
				title_tier = empire
				limit = {
					NOT = {
						this = title:e_latin_empire
					}
				}
				add_to_list = root_old_titles
			}

			every_vassal = {
				limit = {
					primary_title = {
						NOR = {
							this = scope:latin_capital.kingdom
							kingdom = scope:latin_capital.kingdom
							AND = {
								exists = scope:latin_kingdom_2
								kingdom = scope:latin_kingdom_2
							}
							AND = {
								exists = scope:latin_kingdom_2
								this = scope:latin_kingdom_2
							}
						}
					}
				}
				add_to_list = root_old_vassals
			}
			if = {
				limit = {
					top_liege != this
				}
				set_variable = {
					name = old_liege
					value = liege
				}
			}
		}
		if = {
			limit = {
				this != scope:attacker
			}
			add_short_term_gold = ep3_sacking_byz_capital_payoff_value
		}
		custom_tooltip = despoiler_of_byzantium_tooltip
		if = {
			limit = {
				is_allied_to = scope:claimant
			}
			break_alliance = scope:claimant
		}
	}

	#I shall move to the latin empire myself
	option = {
		name = ep3_frankokratia_events.0044.a
		name = {
			trigger = {
				this = scope:latin_empire_receiver
			}
			text = ep3_frankokratia_events.0042.a
		}
		name = {
			trigger = {
				this != scope:latin_empire_receiver
			}
			text = ep3_frankokratia_events.0044.a
		}
		#Add flag to track whether the granting process is complete
		add_to_list = gained_latin_emp_titles

		if = {
			limit = {
				this = scope:latin_empire_receiver
			}
			save_scope_as = latin_emperor
			ep3_frankokratia_grant_latin_empire_effect = yes
			stress_and_fulfillment_impact = {
				arrogant = minor_stress_impact_loss
				zealous = minor_stress_impact_loss
				humble = medium_stress_impact_gain
				content = medium_stress_impact_gain
				lazy = minor_stress_impact_gain
				paranoid = minor_stress_impact_gain
				craven = minor_stress_impact_gain
			}
		}
		else = {
			save_scope_as = latin_title_gainer
			ep3_frankokratia_grant_latin_lands_effect = yes
			stress_and_fulfillment_impact = {
				zealous = minor_stress_impact_loss
				content = medium_stress_impact_gain
				lazy = minor_stress_impact_gain
				paranoid = minor_stress_impact_gain
				craven = minor_stress_impact_gain
			}
		}
		ep3_frankokratia_clear_old_lands_change_capital_effect = yes

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_boldness = 1
				ai_energy = 1
				ai_greed = 1
			}
			modifier = {
				add = 25
				has_trait = zealous
			}
			modifier = {
				add = -25
				OR = {
					has_trait = lazy
					has_trait = paranoid
					has_trait = craven
				}
			}
			modifier = {
				add = -50
				highest_held_title_tier = tier_duchy
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = content
					highest_held_title_tier >= tier_kingdom
				}
			}
		}
	}

	#I choose beneficiary 3
	option = {
		trigger = {
			has_variable = {
				name = emp_beneficiary_3
				name = beneficiary_3
			}
			is_ai = no
		}
		name = {
			trigger = {
				this = scope:latin_empire_receiver
			}
			text = ep3_frankokratia_events.0042.e
		}
		name = {
			trigger = {
				this != scope:latin_empire_receiver
			}
			text = ep3_frankokratia_events.0044.b
		}
		#Add flag to track whether the granting process is complete
		add_to_list = gained_latin_emp_titles
		if = {
			limit = {
				this = scope:latin_empire_receiver
			}
			scope:emp_beneficiary_3 = { save_scope_as = latin_emperor }
			scope:latin_emperor = {
				add_trait = despoiler_of_byzantium
			}
			ep3_frankokratia_grant_latin_empire_effect = yes
			stress_and_fulfillment_impact = {
				trusting = minor_stress_impact_loss
				ambitious = minor_stress_impact_gain
				greedy = minor_stress_impact_gain
				arrogant = minor_stress_impact_gain
			}
		}
		else = {
			scope:beneficiary_3 = {
				save_scope_as = latin_title_gainer
			}
			scope:latin_title_gainer = {
				add_trait = despoiler_of_byzantium
			}
			ep3_frankokratia_grant_latin_lands_effect = yes
		}
	}
	#I choose beneficiary 2
	option = {
		trigger = {
			has_variable = {
				name = emp_beneficiary_2
				name = beneficiary_2
			}
			is_ai = no
		}
		name = {
			trigger = {
				this = scope:latin_empire_receiver
			}
			text = ep3_frankokratia_events.0042.f
		}
		name = {
			trigger = {
				this != scope:latin_empire_receiver
			}
			text = ep3_frankokratia_events.0044.c
		}
		#Add flag to track whether the granting process is complete
		add_to_list = gained_latin_emp_titles
		if = {
			limit = {
				this = scope:latin_empire_receiver
			}
			scope:emp_beneficiary_2 = { save_scope_as = latin_emperor }
			scope:latin_emperor = {
				add_trait = despoiler_of_byzantium
			}
			ep3_frankokratia_grant_latin_empire_effect = yes
			stress_and_fulfillment_impact = {
				trusting = minor_stress_impact_loss
				ambitious = minor_stress_impact_gain
				greedy = minor_stress_impact_gain
				arrogant = minor_stress_impact_gain
			}
		}
		else = {
			scope:beneficiary_2 = {
				save_scope_as = latin_title_gainer
			}
			scope:latin_title_gainer = {
				add_trait = despoiler_of_byzantium
			}
			ep3_frankokratia_grant_latin_lands_effect = yes
		}
	}
	#I choose beneficiary 1
	option = {
		name = {
			trigger = {
				this = scope:latin_empire_receiver
			}
			text = ep3_frankokratia_events.0042.g
		}
		name = {
			trigger = {
				this != scope:latin_empire_receiver
			}
			text = ep3_frankokratia_events.0044.d
		}
		#Add flag to track whether the granting process is complete
		add_to_list = gained_latin_emp_titles
		if = {
			limit = {
				this = scope:latin_empire_receiver
			}
			scope:emp_beneficiary = { save_scope_as = latin_emperor }
			scope:latin_emperor = {
				add_trait = despoiler_of_byzantium
			}
			ep3_frankokratia_grant_latin_empire_effect = yes
			stress_and_fulfillment_impact = {
				trusting = minor_stress_impact_loss
				ambitious = minor_stress_impact_gain
				greedy = minor_stress_impact_gain
				arrogant = minor_stress_impact_gain
			}
		}
		else = {
			scope:beneficiary = {
				save_scope_as = latin_title_gainer
			}
			scope:latin_title_gainer = {
				add_trait = despoiler_of_byzantium
			}
			ep3_frankokratia_grant_latin_lands_effect = yes
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_energy = -1
				ai_boldness = -1
				ai_greed = -1
			}
			modifier = {
				add = 1000
				highest_held_title_tier >= tier_kingdom
			}
			modifier = {
				factor = 0
				OR = {
					is_landed = no
					highest_held_title_tier = tier_barony
				}
			}
		}
	}

	after = {
		clear_saved_scope = beneficiary
		if = {
			limit = {
				exists = scope:beneficiary_2
			}
			clear_saved_scope = beneficiary_2
		}
		if = {
			limit = {
				exists = scope:beneficiary_3
			}
			clear_saved_scope = beneficiary_3
		}

		#If this is the empire receiver, fire title distribution event
		if = {
			limit = {
				this = scope:latin_empire_receiver
			}
			trigger_event = ep3_frankokratia_events.0043
		}
		#If this is a lesser recipient, refire event
		else_if = {
			limit = {
				scope:frankokratia_story = {
					any_in_list = {
						variable = frankokratia_leaders
						NOR = {
							this = scope:latin_empire_receiver
							this = scope:financier
						}
						has_variable = latin_county
						NOT = {
							is_in_list = gained_latin_emp_titles
						}
					}
				}
			}
			scope:frankokratia_story = {
				random_in_list = {
					variable = frankokratia_leaders
					limit = {
						NOR = {
							this = scope:latin_empire_receiver
							this = scope:financier
						}
						has_variable = latin_county
						NOT = {
							is_in_list = gained_latin_emp_titles
						}
					}
					trigger_event = ep3_frankokratia_events.0044
				}
			}
		}
		else = {
			#Distribute counts to dukes
			scope:latin_emperor = { ep3_frankokratia_vassalize_latin_counts_effect = yes }
			#Shatter byzantium event
			title:e_byzantium.holder = {
				trigger_event = {
					id = ep3_frankokratia_events.0050
					days = 1
				}
			}
		}
	}
}

#Latins go home... event for all frankokratia_leaders
ep3_frankokratia_events.0045 = {
	type = character_event
	title = ep3_frankokratia_events.0045.t
	desc = {
		desc = ep3_frankokratia_events.0045.intro
		#Whether capital is Constantinople or elsewhere
		first_valid = {
			triggered_desc = {
				trigger = {
					title:e_byzantium.holder.capital_county = { this = title:c_byzantion }
				}
				desc = ep3_frankokratia_events.0045.intro_constantinople
			}
			desc = ep3_frankokratia_events.0045.intro_generic
		}
		desc = ep3_frankokratia_events.0045.desc
		first_valid = {
			#Whether they are not being paid or being paid off
			triggered_desc = {
				trigger = {
					NOT = {
						scope:claimant = {
							has_character_modifier = bent_before_crusaders_modifier
						}
					}
				}
				desc = ep3_frankokratia_events.0045.unpaid
			}
			desc = ep3_frankokratia_events.0045.paid_off
		}
	}
	#different desc based on whether you were paid at all
	theme = byzantine
	override_background = {
		trigger = {
			title:e_byzantium.holder.capital_county = { this = title:c_byzantion }
		}
		reference = ep3_constantinople
	}
	override_background = {
		trigger = {
			NOT = { title:e_byzantium.holder.capital_county = { this = title:c_byzantion } }
		}
		reference = ep3_city_gate
	}
	left_portrait = {
		character = root
		animation = personality_honorable
		camera = camera_event_left_away
	}

	lower_right_portrait = {
		character = scope:claimant
	}

	immediate = {
		#Show leaving unpaid effects to non-story owner players
		if = {
			limit = {
				this != scope:attacker
				scope:claimant = {
					NOT = {
						has_character_modifier = bent_before_crusaders_modifier
					}
				}
			}
			if = {
				limit = {
					has_lifestyle = martial_lifestyle
				}
				add_martial_lifestyle_xp = medium_lifestyle_xp
			}
			else = {
				add_prestige = medium_prestige_gain
			}
			if = {
				limit = {
					scope:claimant = {
						has_character_flag = swore_to_convert_byz_catholic
					}
				}
				add_piety = major_piety_gain
			}
			else = {
				add_piety = medium_piety_gain
			}
		}
		#Show payoff effects to non-story owner players
		else_if = {
			limit = {
				this != scope:attacker
				scope:claimant = {
					has_character_modifier = bent_before_crusaders_modifier
				}
			}
			scope:claimant = {
				pay_short_term_gold = {
					target = root
					gold = scope:payoff_per_crusader
				}
			}
			if = {
				limit = {
					scope:frankokratia_story = {
						has_variable = crusader_kingdom
						exists = var:crusader_kingdom.holder
						var:crusader_kingdom.holder = {
							faith = scope:attacker.faith
							NOR = {
								is_at_war_with = scope:attacker
								is_at_war_with = scope:claimant
							}
						}
					}
				}
				if = {
					limit = {
						has_trait = excommunicated
					}
					remove_trait = excommunicated
				}
				add_piety = major_piety_gain
				show_as_tooltip = {
					scope:crusader_king = {
						spawn_army = {
							name = ep3_frankokratia_reward_army_name
							uses_supply = yes
							levies = 2600
							men_at_arms = {
								type = cataphract
								stacks = ep3_byz_regiments_ck_value
							}
							location = scope:claimant.capital_province
							inheritable = no
						}
					}
				}
			}
			else = {
				add_piety = minor_piety_gain
				spawn_army = {
					name = ep3_frankokratia_reward_army_name
					uses_supply = yes
					levies = ep3_byz_reward_levy_size_value
					men_at_arms = {
						type = cataphract
						stacks = ep3_byz_regiments_gained_value
					}
					location = scope:claimant.capital_province
				}
			}
		}
		create_character_memory = {
			type = frankokratia_installed_byz_claimant_memory
			participants = {
				claimant = scope:claimant
			}
		}

	}

	#join the crusade, if it's still happening
	option = {
		trigger = {
			exists = faith.religious_head
			faith.religious_head = {
				any_character_war = {
					using_cb = undirected_great_holy_war
					is_attacker = prev

				}
			}
			faith = faith:catholic
		}
		name = ep3_frankokratia_events.0045.a
		add_piety = medium_piety_gain
		faith.religious_head = {
			random_character_war = {
				limit = {
					using_cb = undirected_great_holy_war
				}
				add_attacker = root
			}
		}
		stress_and_fulfillment_impact = {
			cynical = minor_stress_impact_gain
			lazy = minor_stress_impact_gain
			fickle = minor_stress_impact_gain
			craven = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = 2
				ai_honor = 2
			}
			modifier = {
				factor = 0
				OR = {
					any_character_war = {
						is_war_leader = root
					}
					short_term_gold <= medium_gold_value
				}
			}
		}
	}

	#just go home
	option = {
		name = ep3_frankokratia_events.0045.b
		if = {
			limit = {
				exists = faith.religious_head
				faith.religious_head = {
					any_character_war = {
						using_cb = undirected_great_holy_war
						is_attacker = prev
					}
				}
				faith = scope:attacker.faith
			}
			add_piety = major_piety_loss
			stress_and_fulfillment_impact = {
				zealous = major_stress_impact_gain
				diligent = minor_stress_impact_gain
				honest = minor_stress_impact_gain
				stubborn = minor_stress_impact_gain
				just = medium_stress_impact_gain
			}
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_zeal = -2
				ai_honor = -2
			}
		}
	}
}

#Hidden event that fires slaughter interface messages
ep3_frankokratia_events.0046 = {
	hidden = yes
	immediate = {
		save_scope_value_as = {
			name = slaughtered_byzantines
			value = global_var:slaughtered_byzantines
		}
		#Former emperor died, top news
		if = {
			limit = {
				any_in_global_list = {
					variable = slaughtered_byzantines_list
					this = scope:defender
				}
			}
			send_interface_message = {
				type = msg_frankokratia_byz_slaughter
				title = frankokratia_byz_slaughter.t
				left_icon = scope:defender
				desc = frankokratia_byz_slaughter_emp_tooltip
			}
		}
		#A few equally juicy mentions
		else_if = {
			limit = {
				OR = {
					any_in_global_list = {
						variable = slaughtered_byzantines_list
						culture = {
							OR = {
								has_cultural_tradition = tradition_fp1_coastal_warriors
								has_cultural_tradition = tradition_hird
								has_cultural_tradition = tradition_fp1_performative_honour
							}
						}
						can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:claimant }
						is_adult = yes
						prowess >= high_skill_rating
						liege = scope:claimant
					}
					any_in_global_list = {
						variable = slaughtered_byzantines_list
						age < 14
						is_lowborn = no
					}
					any_in_global_list = {
						variable = slaughtered_byzantines_list
						is_landless_administrative = yes
					}
				}
			}
			random_list = {
				#Varangian killed defending palace
				1 = {
					trigger = {
						any_in_global_list = {
							variable = slaughtered_byzantines_list
							culture = {
								OR = {
									has_cultural_tradition = tradition_fp1_coastal_warriors
									has_cultural_tradition = tradition_hird
									has_cultural_tradition = tradition_fp1_performative_honour
								}
							}
							can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:claimant }
							is_adult = yes
							prowess >= high_skill_rating
							liege = scope:claimant
						}
					}
					random_in_global_list = {
						variable = slaughtered_byzantines_list
						limit = {
							culture = {
								OR = {
									has_cultural_tradition = tradition_fp1_coastal_warriors
									has_cultural_tradition = tradition_hird
									has_cultural_tradition = tradition_fp1_performative_honour
								}
							}
							can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = scope:claimant }
							is_adult = yes
							prowess >= high_skill_rating
							liege = scope:claimant
						}
						save_scope_as = varangian_victim
					}
					send_interface_message = {
						type = msg_frankokratia_byz_slaughter
						title = frankokratia_byz_slaughter.t
						left_icon = scope:varangian_victim
						desc = frankokratia_byz_slaughter_varangian_tooltip
					}
				}
				#House head killed
				1 = {
					trigger = {
						any_in_global_list = {
							variable = slaughtered_byzantines_list
							is_landless_administrative = yes
						}
					}
					random_in_global_list = {
						variable = slaughtered_byzantines_list
						limit = {
							is_landless_administrative = yes
						}
						save_scope_as = house_head_victim
					}
					send_interface_message = {
						type = msg_frankokratia_byz_slaughter
						title = frankokratia_byz_slaughter.t
						left_icon = scope:house_head_victim
						desc = frankokratia_byz_slaughter_house_head_tooltip
					}
				}
				#Child killed
				1 = {
					trigger = {
						any_in_global_list = {
							variable = slaughtered_byzantines_list
							age < 14
							is_lowborn = no
						}
					}
					random_in_global_list = {
						variable = slaughtered_byzantines_list
						limit = {
							age < 14
							is_lowborn = no
						}
						save_scope_as = child_victim
					}
					send_interface_message = {
						type = msg_frankokratia_byz_slaughter
						title = frankokratia_byz_slaughter.t
						left_icon = scope:child_victim
						desc = frankokratia_byz_slaughter_child_tooltip
					}
				}
			}
		}
		#No news
		else = {
			send_interface_message = {
				type = msg_frankokratia_byz_slaughter
				title = frankokratia_byz_slaughter.t
				left_icon = scope:latin_capital
				desc = frankokratia_byz_slaughter_tooltip
			}
		}
		every_in_global_list = {
			variable = slaughtered_byzantines_list
			limit = {
				OR = {
					has_any_scripted_relation = root
					is_close_or_extended_family_of = root
					is_consort_of = root
				}
			}
			save_scope_as = victim
			root = {
				send_interface_message = {
					type = msg_frankokratia_byz_slaughter
					title = frankokratia_byz_slaughter_victim.t
					left_icon = scope:victim
					desc = frankokratia_byz_slaughter_victim_tooltip
				}
			}
		}

		if = {
			limit = { root = scope:latin_emperor }
			trigger_event = {
				id = ep3_frankokratia_events.0047
				days = 30
			}
		}
	}
}

#clean up variable
ep3_frankokratia_events.0047 = {
	hidden = yes
	immediate = {
		if = {
			limit = {
				has_global_variable = slaughtered_byzantines
			}
			remove_global_variable = slaughtered_byzantines
		}
		if = {
			limit = {
				has_global_variable_list = slaughtered_byzantines_list
			}
			clear_global_variable_list = slaughtered_byzantines_list
		}
	}
}

#The Byzantine empire shatters
ep3_frankokratia_events.0050 = {
	hidden = yes

	#dang
	option = {
		#Byzantine counties around latin empire are destabilized
		every_realm_county = {
			change_county_control = minor_county_control_loss
		}
		every_realm_county = {
			limit = {
				OR = {
					kingdom = {
						any_de_jure_county = {
							holder = {
								OR = {
									this = scope:latin_emperor
									this = scope:financier
									any_liege_or_above = {
										this = scope:latin_emperor
									}
									any_liege_or_above = {
										this = scope:financier
									}
								}
							}
						}
					}
					duchy = {
						any_de_jure_county = {
							any_neighboring_county = {
								holder = {
									OR = {
										this = scope:latin_emperor
										this = scope:financier
										any_liege_or_above = {
											this = scope:latin_emperor
										}
										any_liege_or_above = {
											this = scope:financier
										}
									}
								}
							}
						}
					}
				}
			}
			change_county_control = medium_county_control_loss
		}
		every_realm_county = {
			limit = {
				any_neighboring_county = {
					holder = {
						OR = {
							this = scope:latin_emperor
							this = scope:financier
							any_liege_or_above = {
								this = scope:latin_emperor
							}
							any_liege_or_above = {
								this = scope:financier
							}
						}
					}
				}
			}
			change_county_control = minor_county_control_loss
		}
		#Make new byz kings and give kings vassals
		ep3_frankokratia_form_byzantine_kingdoms_effect = yes
		#Random counts break off from dukes
		ep3_frankokratia_byzantine_independence_effect = yes
		every_vassal = {
			add_to_list = all_byz_vassals
		}
		#Bye bye Byzantium... and equivalents
		every_held_title = {
			title_tier = empire
			root = {
				destroy_title = prev
			}
		}
		#Release all non-de jure vassals still around
		every_vassal = {
			limit = {
				primary_title = {
					NOT = {
						any_this_title_or_de_jure_above = {
							this = root.primary_title
						}
					}
				}
				highest_held_title_tier >= tier_county
				highest_held_title_tier < tier_kingdom
				government_has_mechanic = administrative
			}
			assign_feudal_governments_effect = yes
			create_character_memory = {
				type = frankokratia_byz_independent_memory
			}
			create_title_and_vassal_change = {
				type = independency
				save_scope_as = change
			}
			becomes_independent = { change = scope:change }
			resolve_title_and_vassal_change = scope:change
		}

		#If the emperor is independent and below king make him and his vassals switch from admin
		if = {
			limit = {
				highest_held_title_tier < tier_kingdom
				OR = {
					NOT = { exists = liege }
					liege = {
						highest_held_title_tier < tier_kingdom
					}
				}
			}
			assign_feudal_governments_effect = yes
			if = {
				limit = {
					any_vassal = {
						is_landed = yes
						government_has_mechanic = administrative
					}
				}
				every_vassal_or_below = {
					limit = {
						is_landed = yes
						government_has_mechanic = administrative
					}
					assign_feudal_governments_effect = yes
				}
			}
		}
	}
	after = {
		#Latin emperor and financier become allies
		if = {
			limit = {
				scope:latin_emperor = {
					NOR = {
						this = scope:financier
						is_allied_to = scope:financier
					}
				}
			}
			scope:latin_emperor = {
				trigger_event = {
					id = ep3_frankokratia_events.0070
					days = 10
				}
			}
		}
		#Latin emperor can consider becoming admin
		scope:latin_emperor = {
			trigger_event = {
				id = ep3_frankokratia_events.0120
				days = 30
			}
		}
		#General event that tells all players what happened
		every_player = {
			limit = {
				ep3_frankokratia_notification_recipient_trigger = yes
			}
			add_character_flag = frankokratia_latin_empire_outcome
			trigger_event = {
				id = ep3_frankokratia_events.0060
				days = 1
			}
		}
		#Force end on story owner to be safe (necessary for AI owner)
		if = {
			limit = {
				global_var:byz_claimant_champion ?= {
					any_owned_story = {
						type = frankokratia_story
					}
				}
			}
			global_var:byz_claimant_champion = {
				trigger_event = {
					id = ep3_frankokratia_events.0061
					days = 3
				}
			}
		}
	}
}

#Other players are informed of what happened - story cycle ends
ep3_frankokratia_events.0060 = {
	type = character_event
	title = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = frankokratia_latin_empire_outcome
				}
				desc = ep3_frankokratia_events.0060.t_latin_empire
			}
			desc = ep3_frankokratia_events.0060.t
		}
	}

	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = frankokratia_latin_empire_outcome
				}
				desc = ep3_frankokratia_events.0060.desc_latin_empire
			}
			triggered_desc = {
				trigger = {
					has_character_flag = frankokratia_crusaders_paid_outcome
				}
				desc = ep3_frankokratia_events.0060.desc_paid
			}
			triggered_desc = {
				trigger = {
					has_character_flag = frankokratia_crusaders_leave_unpaid_outcome
				}
				desc = ep3_frankokratia_events.0060.desc_leave_unpaid
			}
			desc = ep3_frankokratia_events.0060.desc_loss
		}
	}

	theme = byzantine
	override_background = {
		trigger = {
			has_character_flag = frankokratia_latin_empire_outcome
			scope:latin_emperor = {
				any_held_title = {
					this = title:c_byzantion
				}
			}
		}
		reference = ep3_constantinople_riot
	}
	override_background = {
		trigger = {
			has_character_flag = frankokratia_latin_empire_outcome
			NOT = {
				scope:latin_emperor = {
					any_held_title = {
						this = title:c_byzantion
					}
				}
			}
		}
		reference = burning_building
	}
	override_background = {
		trigger = {
			NOT = { has_character_flag = frankokratia_latin_empire_outcome }
			title:e_byzantium.holder.capital_county = { this = title:c_byzantion }
		}
		reference = ep3_constantinople
	}
	override_background = {
		trigger = {
			NOT = { has_character_flag = frankokratia_latin_empire_outcome }
			NOT = {	title:e_byzantium.holder.capital_county = { this = title:c_byzantion } }
		}
		reference = ep3_city_gate
	}

	left_portrait = {
		character = scope:latin_emperor
		triggered_animation = {
			trigger = { religion = religion:christianity_religion }
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
	}

	right_portrait = {
		character = scope:claimant_no_latin_emp
		triggered_animation = {
			trigger = {
				root = {
					has_character_flag = frankokratia_crusaders_lose_outcome
				}
			}
			animation = wailing
		}
		triggered_animation = {
			trigger = {
				religion = religion:christianity_religion
				root = {
					NOT = { has_character_flag = frankokratia_crusaders_lose_outcome }
				}
			}
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
		camera = camera_event_right_forward
	}

	immediate = {
		if = {
			limit = {
				NOT = {
					exists = scope:latin_emperor
				}
			}
			scope:claimant = {
				save_scope_as = claimant_no_latin_emp
			}
		}
		faith:catholic = {
			religious_head = { save_scope_as = pope }
		}
		if = {
			limit = {
				exists = title:e_byzantium.holder
				has_character_flag = frankokratia_crusaders_lose_outcome
			}
			title:e_byzantium.holder = {
				save_scope_as = byz_emperor
			}
		}

		#LATIN EMPIRE
		if = {
			limit = {
				has_character_flag = frankokratia_latin_empire_outcome
			}
			custom_tooltip = latin_emp_title_gain_tooltip
			if = {
				limit = {
					exists = scope:latin_kingdom_1
				}
				custom_tooltip = latin_emp_lesser_gains_tooltip
			}
			if = {
				limit = {
					exists = scope:financier_latin_emp_duchy
				}
				custom_tooltip = financier_gains_duchy_tooltip
			}
			else = {
				custom_tooltip = financier_gains_counties_tooltip
			}
			custom_tooltip = byzantium_is_destroyed_tooltip
			if = {
				limit = {
					global_var:byz_claimant_champion = {
						this = root
					}
				}
				if = {
					limit =	{
						can_set_relation_rival_trigger = {
							CHARACTER = scope:claimant
						}
					}
					scope:claimant = {
						set_relation_rival = {
							target = root
							reason = rival_took_title
						}
					}
				}
				else_if = {
					limit =	{
						can_set_relation_nemesis_trigger = {
							CHARACTER = scope:claimant
						}
					}
					scope:claimant = {
						set_relation_nemesis = {
							target = root
							reason = rival_took_title
						}
					}
				}
			}
		}
		#WAR WAS LOST/WHITE PEACE
		if = {
			limit = {
				has_character_flag = frankokratia_crusaders_lose_outcome
				has_character_flag = frankokratia_crusaders_white_peace_outcome
			}
			custom_tooltip = crusade_claim_white_peace_tooltip
		}
		else_if = {
			limit = {
				has_character_flag = frankokratia_crusaders_lose_outcome
			}
			custom_tooltip = crusade_claim_lose_tooltip
		}
		#WENT HOME PAID
		if = {
			limit = {
				has_character_flag = frankokratia_crusaders_paid_outcome
			}
			custom_tooltip = claimant_became_byz_emp_tooltip
			custom_tooltip = claimant_chose_negative_effects_tooltip
			custom_tooltip = franko_crusaders_gained_gold_special_troops
			show_as_tooltip = {
				scope:claimant.capital_county = {
					add_county_modifier = {
						modifier = crippled_by_imperial_debt_modifier
						years = 25
					}
				}
				scope:claimant = {
					add_character_modifier = {
						modifier = bent_before_crusaders_modifier
						years = 10
					}
				}
			}
		}
		#WENT HOME UNPAID
		if = {
			limit = {
				has_character_flag = frankokratia_crusaders_leave_unpaid_outcome
			}
			custom_tooltip = claimant_became_byz_emp_tooltip
			custom_tooltip = franko_crusaders_depart_unpaid
		}
	}

	option = {
		name = ep3_frankokratia_events.0060.a
		if = {
			limit = {
				has_character_flag = frankokratia_latin_empire_outcome
				is_in_list = non_christian_franko_leaders
			}
			add_trait = despoiler_of_byzantium
			add_gold = major_gold_value
		}
		if = {
			limit = {
				has_character_flag = frankokratia_crusaders_paid_outcome
				is_in_list = non_christian_franko_leaders
			}
			add_gold = medium_gold_value
		}
		if = {
			limit = {
				has_character_flag = frankokratia_latin_empire_outcome
				any_held_title = {
					OR = {
						this = title:e_byzantium
						this = title:e_latin_empire
						empire = title:e_byzantium
						empire = title:e_latin_empire
					}
				}
			}
			scope:latin_emperor = {
				custom_tooltip = gain_latin_dominion_decision_tt
				custom_tooltip = latin_dominion_decision_warning_tt
			}
			scope:latin_emperor = {
				every_vassal = {
					custom = custom.post_byz_greeks
					custom_tooltip = gain_expunge_latins_decision_tt
					custom_tooltip = expunge_latins_decision_warning_tt
					custom_tooltip = restore_byz_empire_notification_tt
				}
			}
			scope:latin_emperor = {
				every_vassal = {
					custom = custom.greek_anarchy_rulers
					custom_tooltip = gain_greek_anarchy_cb_tt
					custom_tooltip = greek_anarchy_cb_warning_tt
				}
			}
		}
	}

	after = {
		if = {
			limit = {
				has_character_flag = frankokratia_latin_empire_outcome
			}
			remove_character_flag = frankokratia_latin_empire_outcome
		}
		if = {
			limit = {
				has_character_flag = frankokratia_crusaders_lose_outcome
			}
			remove_character_flag = frankokratia_crusaders_lose_outcome
		}
		if = {
			limit = {
				has_character_flag = frankokratia_crusaders_white_peace_outcome
			}
			remove_character_flag = frankokratia_crusaders_white_peace_outcome
		}
		if = {
			limit = {
				has_character_flag = frankokratia_crusaders_leave_unpaid_outcome
			}
			remove_character_flag = frankokratia_crusaders_leave_unpaid_outcome
		}
		if = {
			limit = {
				has_character_flag = frankokratia_crusaders_paid_outcome
			}
			remove_character_flag = frankokratia_crusaders_paid_outcome
		}

		if = {
			limit = {
				any_owned_story = {
					type = frankokratia_story
				}
			}
			ep3_frankokratia_end_story_effect = yes
		}
	}
}

#Force story end on AI
ep3_frankokratia_events.0061 = {
	hidden = yes
	immediate = {
		if = {
			limit = {
				any_owned_story = {
					type = frankokratia_story
				}
			}
			ep3_frankokratia_end_story_effect = yes
		}
	}
}

#Financier suggests being allies to Latin Emperor
ep3_frankokratia_events.0070 = {
	type = character_event
	title = ep3_frankokratia_events.0070.t
	desc = {
		desc = ep3_frankokratia_events.0070.intro
		#Whether emperor led crusade or not
		first_valid = {
			triggered_desc = {
				trigger = {
					this != scope:byz_claimant_champion
				}
				desc = ep3_frankokratia_events.0070.rando_emp
			}
			desc = ep3_frankokratia_events.0070.leader_emp
		}
		desc = ep3_frankokratia_events.0070.desc
	}
	theme = byzantine
	override_background = ep3_byzantium_throneroom
	left_portrait = {
		character = root
		animation = emotion_thinking_scepter
	}
	right_portrait = {
		character = scope:financier
		animation = toast_goblet
	}

	trigger = {
		is_alive = yes
		primary_title = title:e_latin_empire
		exists = scope:financier
		NOR = {
			is_at_war_with = scope:financier
			is_allied_to = scope:financier
		}
		scope:financier = {
			NOR = {
				highest_held_title_tier <= tier_barony
				is_incapable = yes
				is_vassal_or_below_of = root
				is_liege_or_above_of = root
			}
		}
	}

	immediate = {
		if = {
			limit = {
				any_realm_county = {
					duchy = title:d_istria
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					duchy = title:d_istria
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					duchy = title:d_ragusa
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					duchy = title:d_ragusa
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					duchy = title:d_dalmatia
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					duchy = title:d_dalmatia
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					duchy = title:d_cephalonia
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					duchy = title:d_cephalonia
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					duchy = title:d_krete
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					duchy = title:d_krete
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					duchy = title:d_cyprus
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					duchy = title:d_cyprus
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					duchy = title:d_aegean_islands
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					duchy = title:d_aegean_islands
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					duchy = title:d_crimea
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					duchy = title:d_crimea
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					this = title:c_zadar
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					this = title:c_zadar
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					this = title:c_cherso
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					this = title:c_cherso
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					this = title:c_dyrrachion
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					this = title:c_euboea
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					this = title:c_euboea
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					this = title:c_euboea
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					this = title:c_messenia
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					this = title:c_messenia
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					this = title:c_kalliopolis
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					this = title:c_kalliopolis
				}
				save_scope_as = financier_claim
			}
		}
		else_if = {
			limit = {
				any_realm_county = {
					has_coastal_province = yes
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
			}
			random_realm_county = {
				limit = {
					has_coastal_province = yes
					NOT = {
						scope:financier = {
							has_claim_on = prev
						}
					}
				}
				save_scope_as = financier_claim
			}
		}
	}
	#Together, we will profit in these Greek lands
	option = {
		name = ep3_frankokratia_events.0070.a
		flavor = ep3_frankokratia_events.0070.a.flavor
		custom_tooltip = negotiate_financier_alliance_effect_tooltip
		create_alliance = {
			target = scope:financier
			allied_through_owner = root
			allied_through_target = scope:financier
		}
		scope:financier = {
			add_opinion = {
				target = root
				modifier = event_negotiated_alliance_opinion
			}
		}
		every_realm_county = {
			custom = custom.every_realm_county
			add_county_modifier = {
				modifier = egregious_trading_rights_modifier
				years = 30
			}
		}
		scope:financier.capital_county = {
			add_county_modifier = {
				modifier = greek_spoils_imports_modifier
				years = 30
			}
		}
		stress_and_fulfillment_impact = {
			generous = minor_stress_impact_loss
			greedy = medium_stress_impact_gain
			arrogant = medium_stress_impact_gain
			paranoid = minor_stress_impact_gain
			brave = minor_stress_impact_gain
			wrathful = minor_stress_impact_gain
			fickle = minor_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = -1
				ai_boldness = -1
			}
			modifier = {
				add = 100
				opinion = {
					target = scope:financier
					value <= -40
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = greedy
					has_trait = arrogant
					opinion = {
						target = scope:financier
						value <= -80
					}
				}
			}
		}
	}
	#You avaricious traders shall bend to ME!
	option = {
		name = ep3_frankokratia_events.0070.b
		flavor = ep3_frankokratia_events.0070.b.flavor
		every_vassal = {
			custom = custom.every_vassal
			limit = {
				NOR = {
					is_allied_to = scope:financier
					has_relation_friend = scope:financier
					is_close_or_extended_family_of = scope:financier
				}
			}
			add_opinion = {
				modifier = pleased_opinion
				target = root
				opinion = 20
			}
		}
		add_character_modifier = {
			modifier = ep3_harassed_at_sea_modifier
			years = 20
		}
		scope:financier = {
			set_relation_rival = {
				target = root
				reason = rival_latin_emp_refused_alliance
			}
			add_opinion = {
				modifier = angry_opinion
				target = root
				opinion = -50
			}
			if = {
				limit = {
					exists = scope:financier_claim
				}
				add_pressed_claim = scope:financier_claim
			}
		}
		stress_and_fulfillment_impact = {
			generous = medium_stress_impact_gain
			craven = medium_stress_impact_gain
			humble = minor_stress_impact_gain
			trusting = medium_stress_impact_gain
		}
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 1
				ai_boldness = 1
			}
			modifier = {
				add = 100
				opinion = {
					target = scope:financier
					value >= 40
				}
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = craven
					has_trait = generous
					has_trait = trusting
					opinion = {
						target = scope:financier
						value >= 80
					}
				}
			}
		}
	}
}

scripted_trigger ep3_frankokratia_events_0080_kingdom_trigger = {
	tier = tier_kingdom
	holder ?= {
		top_liege = root
	}
	OR = {
		any_de_jure_county = {
			this = root.capital_county
		}
		any_de_jure_county = {
			percent >= 0.8
			holder.top_liege = {
				this = root
			}
		}
	}
	NOT = {
		this = title:e_byzantium
	}
}

#Decision event for gaining latin de jure kingdom
ep3_frankokratia_events.0080 = {
	type = character_event
	title = ep3_frankokratia_events.0080.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					culture = {
						NOR = {
							this = culture:greek
							has_cultural_pillar = language_greek
							any_parent_culture_or_above = {
								this = culture:greek
							}
						}
					}
				}
				desc = ep3_frankokratia_events.0080_non_greek
			}
			desc = ep3_frankokratia_events.0080_greek
		}
		desc = ep3_frankokratia_events.0080.desc
	}
	theme = byzantine
	override_background = ep3_city_gate
	override_effect_2d = {
		reference = legend_glow
	}
	left_portrait = {
		character = root
		animation = jockey_wave
		camera = camera_event_horse_left_forward
	}
	right_portrait = {
		character = scope:happy_dude
		animation = marshal_axe
		camera = camera_event_right_forward
	}

	immediate = {
		title:e_byzantium = {
			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						any_de_jure_county = {
							this = root.capital_county
						}
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						any_de_jure_county = {
							this = root.capital_county
						}
					}
					save_scope_as = kingdom_1
				}
			}
			else = {
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
					}
					save_scope_as = kingdom_1
				}
			}

			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						this != scope:kingdom_1
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						this != scope:kingdom_1
					}
					save_scope_as = kingdom_2
				}
			}
			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
						}
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
						}
					}
					save_scope_as = kingdom_3
				}
			}
			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
							this = scope:kingdom_3
						}
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
							this = scope:kingdom_3
						}
					}
					save_scope_as = kingdom_4
				}
			}
			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
							this = scope:kingdom_3
							this = scope:kingdom_4
						}
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0080_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
							this = scope:kingdom_3
							this = scope:kingdom_4
						}
					}
					save_scope_as = kingdom_5
				}
			}
		}
		if = {
			limit = {
				any_knight = {
					is_imprisoned = no
					is_ruler = no
				}
			}
			random_knight = {
				limit = {
					is_imprisoned = no
					is_ruler = no
				}
				save_scope_as = happy_dude
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_imprisoned = no
					is_ruler = no
					is_adult = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
			}
			random_courtier = {
				limit = {
					is_imprisoned = no
					is_ruler = no
					is_adult = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				save_scope_as = happy_dude
			}
		}
		if = {
			limit = {
				exists = scope:happy_dude
			}
			scope:happy_dude = {
				add_character_flag = need_military_outfit
			}
		}
	}
	option = {
		name = ep3_frankokratia_events.0080.a
		scope:kingdom_1 = {
			set_de_jure_liege_title = title:e_latin_empire
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					exists = holder
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
				if = {
					limit = {
						culture = {
							NOR = {
								this = root.culture
								is_in_list = kingdom_cultures
							}
						}
					}
					culture = {
						add_to_list = kingdom_cultures
					}
				}
			}
			save_scope_as = swapped_kingdom
		}
		every_in_list = {
			list = kingdom_cultures
			change_cultural_acceptance = {
				target = root.culture
				value = medium_cultural_acceptance_value
				desc = cultural_acceptance_latins_legitimized
			}
		}
		if = {
			limit = {
				scope:kingdom_1.holder = {
					this != root
				}
			}
			reverse_add_opinion = {
				target = scope:kingdom_1.holder
				modifier = loyalty_opinion
				opinion = 40
			}
		}
		else_if = {
			limit = {
				government_has_flag = government_has_influence
			}
			change_influence = major_influence_gain
		}
		else = {
			add_legitimacy = medium_legitimacy_gain
		}
		custom_tooltip = latin_de_jure_lost_on_title_loss_tt
		custom_tooltip = byzantines_threaten_latin_titles_tt
	}
	option = {
		trigger = {
			exists = scope:kingdom_2
			is_ai = no
		}
		name = ep3_frankokratia_events.0080.b
		scope:kingdom_2 = {
			set_de_jure_liege_title = title:e_latin_empire
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					exists = holder
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
				if = {
					limit = {
						culture = {
							NOR = {
								this = root.culture
								is_in_list = kingdom_cultures
							}
						}
					}
					culture = {
						add_to_list = kingdom_cultures
					}
				}
			}
			save_scope_as = swapped_kingdom
		}
		every_in_list = {
			list = kingdom_cultures
			change_cultural_acceptance = {
				target = root.culture
				value = medium_cultural_acceptance_value
				desc = cultural_acceptance_latins_legitimized
			}
		}
		if = {
			limit = {
				scope:kingdom_2.holder = {
					this != root
				}
			}
			reverse_add_opinion = {
				target = scope:kingdom_2.holder
				modifier = loyalty_opinion
				opinion = 40
			}
		}
		else_if = {
			limit = {
				government_has_flag = government_has_influence
			}
			change_influence = major_influence_gain
		}
		else = {
			add_legitimacy = medium_legitimacy_gain
		}
		custom_tooltip = latin_de_jure_lost_on_title_loss_tt
		custom_tooltip = byzantines_threaten_latin_titles_tt
	}

	option = {
		trigger = {
			exists = scope:kingdom_3
			is_ai = no
		}
		name = ep3_frankokratia_events.0080.c
		scope:kingdom_3 = {
			set_de_jure_liege_title = title:e_latin_empire
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					exists = holder
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
				if = {
					limit = {
						culture = {
							NOR = {
								this = root.culture
								is_in_list = kingdom_cultures
							}
						}
					}
					culture = {
						add_to_list = kingdom_cultures
					}
				}
			}
			save_scope_as = swapped_kingdom
		}
		every_in_list = {
			list = kingdom_cultures
			change_cultural_acceptance = {
				target = root.culture
				value = medium_cultural_acceptance_value
				desc = cultural_acceptance_latins_legitimized
			}
		}
		if = {
			limit = {
				scope:kingdom_3.holder = {
					this != root
				}
			}
			reverse_add_opinion = {
				target = scope:kingdom_3.holder
				modifier = loyalty_opinion
				opinion = 40
			}
		}
		else_if = {
			limit = {
				government_has_flag = government_has_influence
			}
			change_influence = major_influence_gain
		}
		else = {
			add_legitimacy = medium_legitimacy_gain
		}
		custom_tooltip = latin_de_jure_lost_on_title_loss_tt
		custom_tooltip = byzantines_threaten_latin_titles_tt
	}

	option = {
		trigger = {
			exists = scope:kingdom_4
			is_ai = no
		}
		name = ep3_frankokratia_events.0080.d
		scope:kingdom_4 = {
			set_de_jure_liege_title = title:e_latin_empire
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					exists = holder
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
				if = {
					limit = {
						culture = {
							NOR = {
								this = root.culture
								is_in_list = kingdom_cultures
							}
						}
					}
					culture = {
						add_to_list = kingdom_cultures
					}
				}
			}
			save_scope_as = swapped_kingdom
		}
		every_in_list = {
			list = kingdom_cultures
			change_cultural_acceptance = {
				target = root.culture
				value = medium_cultural_acceptance_value
				desc = cultural_acceptance_latins_legitimized
			}
		}
		if = {
			limit = {
				scope:kingdom_4.holder = {
					this != root
				}
			}
			reverse_add_opinion = {
				target = scope:kingdom_4.holder
				modifier = loyalty_opinion
				opinion = 40
			}
		}
		else_if = {
			limit = {
				government_has_flag = government_has_influence
			}
			change_influence = major_influence_gain
		}
		else = {
			add_legitimacy = medium_legitimacy_gain
		}
		custom_tooltip = latin_de_jure_lost_on_title_loss_tt
		custom_tooltip = byzantines_threaten_latin_titles_tt
	}

	option = {
		trigger = {
			exists = scope:kingdom_5
			is_ai = no
		}
		name = ep3_frankokratia_events.0080.e
		scope:kingdom_5 = {
			set_de_jure_liege_title = title:e_latin_empire
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					exists = holder
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
				if = {
					limit = {
						culture = {
							NOR = {
								this = root.culture
								is_in_list = kingdom_cultures
							}
						}
					}
					culture = {
						add_to_list = kingdom_cultures
					}
				}
			}
			save_scope_as = swapped_kingdom
		}
		every_in_list = {
			list = kingdom_cultures
			change_cultural_acceptance = {
				target = root.culture
				value = medium_cultural_acceptance_value
				desc = cultural_acceptance_latins_legitimized
			}
		}
		if = {
			limit = {
				scope:kingdom_5.holder = {
					this != root
				}
			}
			reverse_add_opinion = {
				target = scope:kingdom_5.holder
				modifier = loyalty_opinion
				opinion = 40
			}
		}
		else_if = {
			limit = {
				government_has_flag = government_has_influence
			}
			change_influence = major_influence_gain
		}
		else = {
			add_legitimacy = medium_legitimacy_gain
		}
		custom_tooltip = latin_de_jure_lost_on_title_loss_tt
		custom_tooltip = byzantines_threaten_latin_titles_tt
	}
	after = {
		if = {
			limit = {
				exists = scope:happy_dude
			}
			scope:happy_dude = {
				remove_character_flag = need_military_outfit
			}
		}
		save_scope_as = title_gainer
		#Send notification out to everyone in de jure latin empire
		if = {
			limit = {
				title:e_latin_empire = {
					any_in_de_jure_hierarchy = {
						holder ?= {
							is_ai = no
							this != root
						}
					}
				}
			}
			title:e_latin_empire = {
				every_in_de_jure_hierarchy = {
					limit = {
						holder ?= {
							is_ai = no
							this != root
						}
					}
					if = {
						limit = {
							holder ?= {
								NOT = { is_in_list = latin_byz_notify }
							}
						}
						holder = {
							add_to_list = latin_byz_notify
						}
					}
				}
			}
		}
		if = {
			limit = {
				title:e_byzantium = {
					any_in_de_jure_hierarchy = {
						holder ?= {
							is_ai = no
							this != root
						}
					}
				}
			}
			title:e_byzantium = {
				every_in_de_jure_hierarchy = {
					limit = {
						holder ?= {
							is_ai = no
							this != root
						}
					}
					if = {
						limit = {
							holder = {
								NOT = { is_in_list = latin_byz_notify }
							}
						}
						holder = {
							add_to_list = latin_byz_notify
						}
					}
				}
			}
		}
		trigger_event = ep3_frankokratia_events.0081
		create_character_memory = {
			type = frankokratia_latin_kingdom_memory
			participants = {
				swapped_kingdom = scope:swapped_kingdom
			}
		}
	}
}

ep3_frankokratia_events.0081 = {
	hidden = yes
	immediate = {
		save_scope_as = title_gainer
		every_in_list = {
			list = latin_byz_notify
			send_interface_message = {
				type = msg_byz_latin_de_jure_switch
				title = msg_latin_de_jure_gain.t
				desc = msg_latin_de_jure_gain.desc
				left_icon = scope:title_gainer
				right_icon = scope:swapped_kingdom
			}
		}
	}
}

scripted_trigger ep3_frankokratia_events_0090_kingdom_trigger = {
	tier = tier_kingdom

	NOT = { this = title:e_latin_empire }
	OR = {
		#Controls entire kingdom
		any_de_jure_county = {
			percent >= 1
			holder.top_liege = {
				this = root
			}
		}
		#Controls half and has de jure title
		AND = {
			holder ?= {
				top_liege = root
			}
			OR = {
				any_de_jure_county = {
					this = root.capital_county
				}
				any_de_jure_county = {
					percent >= 0.5
					holder.top_liege = {
						this = root
					}
				}
			}
		}
	}
}

##Decision event for returning latin de jure kingdoms to byzantine
ep3_frankokratia_events.0090 = {
	type = character_event
	title = ep3_frankokratia_events.0090.t
	desc = {
		desc = ep3_frankokratia_events.0090.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					primary_title = title:e_byzantium
					culture = {
						has_cultural_pillar = language_greek
					}
				}
				desc = ep3_frankokratia_events.0090_emp
			}
			desc = ep3_frankokratia_events.0090_non_emp
		}
	}
	theme = byzantine
	override_background = {
		trigger = {
			scope:kingdom_1 = {
				any_de_jure_county = {
					faith.religion = religion:christianity_religion
					any_county_province = {
						OR = {
							geographical_region = world_europe_south
							geographical_region = world_asia_minor
							geographical_region = world_middle_east
							geographical_region = world_africa_north
						}
					}
				}
			}
		}
		reference = ep3_holy_site_orthodox
	}
	override_background = {
		trigger = {
			NOT = {
				scope:kingdom_1 = {
					any_de_jure_county = {
						faith.religion = religion:christianity_religion
						any_county_province = {
							OR = {
								geographical_region = world_europe_south
								geographical_region = world_asia_minor
								geographical_region = world_middle_east
								geographical_region = world_africa_north
							}
						}
					}
				}
			}
			scope:kingdom_1 = {
				any_de_jure_county = {
					OR = {
						has_graphical_mediterranean_culture_group_trigger = yes
						has_graphical_iberian_culture_group_trigger = yes
					}
				}
			}
		}
		reference = ep3_medi_market
	}
	override_background = {
		trigger = {
			NOT = {
				scope:kingdom_1 = {
					any_de_jure_county = {
						faith.religion = religion:christianity_religion
						any_county_province = {
							OR = {
								geographical_region = world_europe_south
								geographical_region = world_asia_minor
								geographical_region = world_middle_east
								geographical_region = world_africa_north
							}
						}
					}
				}
			}
			scope:kingdom_1 = {
				any_de_jure_county = {
					has_graphical_western_culture_group_trigger = yes
				}
			}
		}
		reference = market_west
	}
	override_background = {
		trigger = {
			NOT = {
				scope:kingdom_1 = {
					any_de_jure_county = {
						faith.religion = religion:christianity_religion
						any_county_province = {
							OR = {
								geographical_region = world_europe_south
								geographical_region = world_asia_minor
								geographical_region = world_middle_east
								geographical_region = world_africa_north
							}
						}
					}
				}
			}
			scope:kingdom_1 = {
				any_de_jure_county = {
					OR = {
						has_graphical_mena_culture_group_trigger = yes
						has_graphical_iranian_culture_group_trigger = yes
						has_graphical_india_culture_group_trigger = yes
						has_graphical_african_culture_group_trigger = yes
					}
				}
			}
		}
		reference = market_east
	}
	override_background = {
		trigger = {
			NOT = {
				scope:kingdom_1 = {
					any_de_jure_county = {
						faith.religion = religion:christianity_religion
						any_county_province = {
							OR = {
								geographical_region = world_europe_south
								geographical_region = world_asia_minor
								geographical_region = world_middle_east
								geographical_region = world_africa_north
							}
						}
					}
				}
			}
			scope:kingdom_1 = {
				any_de_jure_county = {
					has_graphical_norse_culture_group_trigger = yes
				}
			}
		}
		reference = market_tribal
	}
	override_background = {
		trigger = {
			NOT = {
				scope:kingdom_1 = {
					any_de_jure_county = {
						faith.religion = religion:christianity_religion
						any_county_province = {
							OR = {
								geographical_region = world_europe_south
								geographical_region = world_asia_minor
								geographical_region = world_middle_east
								geographical_region = world_africa_north
							}
						}
					}
				}
			}
			scope:kingdom_1 = {
				any_de_jure_county = {
					has_graphical_steppe_culture_group_trigger = yes
				}
			}
		}
		reference = ep2_travel_settlement_steppe
	}
	override_background = {
		trigger = {
			NOT = {
				scope:kingdom_1 = {
					any_de_jure_county = {
						faith.religion = religion:christianity_religion
						any_county_province = {
							OR = {
								geographical_region = world_europe_south
								geographical_region = world_asia_minor
								geographical_region = world_middle_east
								geographical_region = world_africa_north
							}
						}
					}
				}
			}
		}
		reference = market
	}
	override_effect_2d = {
		reference = legend_glow
	}
	left_portrait = {
		character = root
		animation = jockey_wave
		camera = camera_event_horse_left_forward
	}
	right_portrait = {
		character = scope:happy_dude
		animation = marshal_mace
		camera = camera_event_right_forward
	}

	immediate = {
		title:e_latin_empire = {
			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						any_de_jure_county = {
							this = root.capital_county
						}
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						any_de_jure_county = {
							this = root.capital_county
						}
					}
					save_scope_as = kingdom_1
				}
			}
			else = {
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
					}
					save_scope_as = kingdom_1
				}
			}

			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						this != scope:kingdom_1
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						this != scope:kingdom_1
					}
					save_scope_as = kingdom_2
				}
			}
			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
						}
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
						}
					}
					save_scope_as = kingdom_3
				}
			}
			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
							this = scope:kingdom_3
						}
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
							this = scope:kingdom_3
						}
					}
					save_scope_as = kingdom_4
				}
			}
			if = {
				limit = {
					any_in_de_jure_hierarchy = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
							this = scope:kingdom_3
							this = scope:kingdom_4
						}
					}
				}
				random_in_de_jure_hierarchy = {
					limit = {
						ep3_frankokratia_events_0090_kingdom_trigger = yes
						NOR = {
							this = scope:kingdom_1
							this = scope:kingdom_2
							this = scope:kingdom_3
							this = scope:kingdom_4
						}
					}
					save_scope_as = kingdom_5
				}
			}
		}
		if = {
			limit = {
				any_knight = {
					is_imprisoned = no
					is_ruler = no
				}
			}
			random_knight = {
				limit = {
					is_imprisoned = no
					is_ruler = no
				}
				save_scope_as = happy_dude
			}
		}
		else_if = {
			limit = {
				any_courtier = {
					is_imprisoned = no
					is_ruler = no
					is_adult = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
			}
			random_courtier = {
				limit = {
					is_imprisoned = no
					is_ruler = no
					is_adult = yes
					can_be_combatant_based_on_gender_trigger = { ARMY_OWNER = root }
				}
				save_scope_as = happy_dude
			}
		}
		if = {
			limit = {
				exists = scope:happy_dude
			}
			scope:happy_dude = {
				add_character_flag = need_military_outfit
			}
		}
	}
	option = {
		name = ep3_frankokratia_events.0090.a
		scope:kingdom_1 = {
			set_de_jure_liege_title = title:e_byzantium
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
			}
			save_scope_as = swapped_kingdom
		}
		if = {
			limit = {
				NOR = {
					any_held_title = {
						this = scope:kingdom_1
					}
					has_strong_claim_on = scope:kingdom_1
				}
			}
			add_pressed_claim = scope:kingdom_1
		}
		expunge_latin_dominion_effect = yes
	}
	option = {
		trigger = {
			exists = scope:kingdom_2
			is_ai = no
		}
		name = ep3_frankokratia_events.0090.b
		scope:kingdom_2 = {
			set_de_jure_liege_title = title:e_byzantium
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
			}
			save_scope_as = swapped_kingdom
		}
		if = {
			limit = {
				NOR = {
					any_held_title = {
						this = scope:kingdom_2
					}
					has_strong_claim_on = scope:kingdom_2
				}
			}
			add_pressed_claim = scope:kingdom_2
		}
		expunge_latin_dominion_effect = yes
	}

	option = {
		trigger = {
			exists = scope:kingdom_3
			is_ai = no
		}
		name = ep3_frankokratia_events.0090.c
		scope:kingdom_3 = {
			set_de_jure_liege_title = title:e_byzantium
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
			}
			save_scope_as = swapped_kingdom
		}
		if = {
			limit = {
				NOR = {
					any_held_title = {
						this = scope:kingdom_3
					}
					has_strong_claim_on = scope:kingdom_3
				}
			}
			add_pressed_claim = scope:kingdom_3
		}
		expunge_latin_dominion_effect = yes
	}

	option = {
		trigger = {
			exists = scope:kingdom_4
			is_ai = no
		}
		name = ep3_frankokratia_events.0090.d
		scope:kingdom_4 = {
			set_de_jure_liege_title = title:e_byzantium
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
			}
			save_scope_as = swapped_kingdom
		}
		if = {
			limit = {
				NOR = {
					any_held_title = {
						this = scope:kingdom_4
					}
					has_strong_claim_on = scope:kingdom_4
				}
			}
			add_pressed_claim = scope:kingdom_4
		}
		expunge_latin_dominion_effect = yes
	}

	option = {
		trigger = {
			exists = scope:kingdom_5
			is_ai = no
		}
		name = ep3_frankokratia_events.0090.e
		scope:kingdom_5 = {
			set_de_jure_liege_title = title:e_byzantium
			every_de_jure_county = {
				custom = custom.every_county_latin_kingdom
				limit = {
					holder.top_liege = {
						this = root
					}
					holder = {
						NOT = {
							is_at_war_with = root
						}
					}
				}
				change_county_control = medium_county_control_gain
			}
			save_scope_as = swapped_kingdom
		}
		if = {
			limit = {
				NOR = {
					any_held_title = {
						this = scope:kingdom_5
					}
					has_strong_claim_on = scope:kingdom_5
				}
			}
			add_pressed_claim = scope:kingdom_5
		}
		expunge_latin_dominion_effect = yes
	}
	after = {
		if = {
			limit = {
				exists = scope:happy_dude
			}
			scope:happy_dude = {
				remove_character_flag = need_military_outfit
			}
		}
		#Send notification out to everyone in de jure latin empire
		if = {
			limit = {
				title:e_latin_empire = {
					any_in_de_jure_hierarchy = {
						holder ?= {
							is_ai = no
							this != root
						}
					}
				}
			}
			title:e_latin_empire = {
				every_in_de_jure_hierarchy = {
					limit = {
						holder ?= {
							is_ai = no
							this != root
						}
					}
					if = {
						limit = {
							holder = {
								NOT = { is_in_list = latin_byz_notify }
							}
						}
						holder = {
							add_to_list = latin_byz_notify
						}
					}
				}
			}
		}
		if = {
			limit = {
				title:e_byzantium = {
					any_in_de_jure_hierarchy = {
						holder ?= {
							is_ai = no
							this != root
						}
					}
				}
			}
			title:e_byzantium = {
				every_in_de_jure_hierarchy = {
					limit = {
						holder ?= {
							is_ai = no
							this != root
						}
					}
					if = {
						limit = {
							holder = {
								NOT = { is_in_list = latin_byz_notify }
							}
						}
						holder = {
							add_to_list = latin_byz_notify
						}
					}
				}
			}
		}
		trigger_event = ep3_frankokratia_events.0091
		create_character_memory = {
			type = frankokratia_byz_kingdom_memory
			participants = {
				swapped_kingdom = scope:swapped_kingdom
			}
		}
	}
}

ep3_frankokratia_events.0091 = {
	hidden = yes
	immediate = {
		save_scope_as = title_gainer
		every_in_list = {
			list = latin_byz_notify
			send_interface_message = {
				type = msg_byz_latin_de_jure_switch
				title = msg_byz_de_jure_gain.t
				desc = msg_byz_de_jure_gain.desc
				left_icon = scope:title_gainer
				right_icon = scope:swapped_kingdom
			}
		}
	}
}

#The Latin Empire has fallen
ep3_frankokratia_events.0100 = {
	type = character_event
	title = ep3_frankokratia_events.0100.t
	desc = {
		desc = ep3_frankokratia_events.0100.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					NOT = {
						exists = title:e_byzantium.holder
					}
					OR = {
						culture = culture:greek
						culture = {
							any_parent_culture_or_above = {
								this = culture:greek
							}
						}
						ep3_orthodox_faith_trigger = yes
					}
				}
				desc = ep3_frankokratia_events.0100.byz_no_emp
			}
			triggered_desc = {
				trigger = {
					NOT = {
						exists = title:e_byzantium.holder
					}
					OR = {
						faith = faith:catholic
						this = scope:latin_emp
					}
				}
				desc = ep3_frankokratia_events.0100.cath
			}
			triggered_desc = {
				trigger = {
					exists = title:e_byzantium.holder
				}
				desc = ep3_frankokratia_events.0100.emp
			}
		}
	}
	theme = byzantine
	override_background = {
		trigger = {
			scope:latin_emp.location.county = {
				this = title:c_byzantion
			}
		}
		reference = ep3_hagia_sophia
	}
	override_background = {
		trigger = {
			scope:latin_emp = {
				faith.religion = religion:christianity_religion
				location.county = {
					NOT = { this = title:c_byzantion }
				}
			}
		}
		reference = temple_church
	}
	override_background = {
		trigger = {
			scope:latin_emp = {
				faith.religion = religion:islam_religion
				location.county = {
					NOT = { this = title:c_byzantion }
				}
			}
		}
		reference = temple_mosque
	}
	override_background = {
		trigger = {
			scope:latin_emp = {
				NOR = {
					faith.religion = religion:islam_religion
					faith.religion = religion:christianity_religion
				}
				location.county = {
					NOT = { this = title:c_byzantion }
				}
			}
		}
		reference = temple_generic
	}
	left_portrait = {
		character = scope:latin_emp
		triggered_animation = {
			trigger = {
				scope:latin_emp = {
					is_alive = no
				}
			}
			animation = dead
		}
		triggered_animation = {
			trigger = {
				scope:latin_emp = {
					is_alive = yes
				}
			}
			animation = throne_room_curtsey_1
		}
	}
	lower_right_portrait = scope:byz_emp
	immediate = {
		if = {
			limit = {
				exists = title:e_byzantium.holder
			}
			title:e_byzantium.holder = {
				save_scope_as = byz_emp
			}
		}
		add_character_flag = {
			flag = had_ep3_frankokratia_events_0100
			days = 30
		}
	}
	#Well that's over
	option = {
		name = {
			trigger = {
				NOR = {
					faith = faith:catholic
					this = scope:latin_emp
				}
			}
			text = ep3_frankokratia_events.0100.a_non_catholic
		}
		name = {
			trigger = {
				OR = {
					faith = faith:catholic
					this = scope:latin_emp
				}
			}
			text = ep3_frankokratia_events.0100.a_catholic
		}
		#Swap titles if root is the latin emperor
		if = {
			limit = {
				root = scope:latin_emp
				scope:landed_title = {
					any_in_de_jure_hierarchy = {
						tier <= tier_kingdom
					}
				}
			}
			scope:landed_title = {
				every_in_de_jure_hierarchy = {
					limit = {
						tier = tier_kingdom
					}
					set_de_jure_liege_title = title:e_byzantium
				}
			}
		}
		#Tell everyone else it's gonna happen
		else_if = {
			limit = {
				scope:landed_title = {
					any_in_de_jure_hierarchy = {
						tier <= tier_kingdom
					}
				}
			}
			custom_tooltip = swap_latin_for_byz_titles_tt
		}
	}
}

scripted_trigger ep3_frankokratia_events_0110_favorite_vassal_trigger = {
	is_vassal_of = scope:emperor
	scope:previous_holder = {
		is_alive = yes
		is_imprisoned = no
		is_incapable = no
		is_landed = no
	}
	scope:emperor = {
		OR = {
			#No vassal who former emp likes more
			NOT = {
				any_vassal = {
					highest_held_title_tier >= tier_county
					is_landed = yes
					reverse_opinion = {
						target = scope:previous_holder
						value >= "scope:previous_holder.opinion(scope:vassal)"
					}
				}
			}
			#No stronger vassal who former emp likes the same
			NOT = {
				any_vassal = {
					highest_held_title_tier >= tier_county
					is_landed = yes
					reverse_opinion = {
						target = scope:previous_holder
						value > "scope:previous_holder.opinion(scope:vassal)"
					}
					current_military_strength > root.current_military_strength
				}
			}
		}
	}
}

scripted_trigger ep3_frankokratia_events_0110_potential_king_trigger = {
	is_landed = yes
	OR = {
		#is already a king, duh
		highest_held_title_tier >= tier_kingdom
		#Can make them a kingdom
		AND = {
			capital_county = {
				kingdom = {
					NOR = {
						exists = holder
						#Desperately try to stop latin kingdoms being grabbed
						trigger_if = {
							limit = {
								exists = global_var:latin_kingdom_1
							}
							this = global_var:latin_kingdom_1
						}
						trigger_if = {
							limit = {
								exists = global_var:latin_kingdom_2
							}
							this = global_var:latin_kingdom_2
						}
						any_in_de_jure_hierarchy = {
							tier = tier_county
							this = scope:emperor.capital_county
						}
						AND = {
							scope:emperor = {
								any_realm_county = {
									this = title:c_byzantion
								}
								any_realm_county = {
									kingdom = title:k_hellas
								}
							}
							this = title:k_hellas
						}
					}
				}
			}
			highest_held_title_tier >= tier_duchy
			exists = liege
			#Must be free of any liege that isn't the emperor
			NOT = {
				liege = {
					highest_held_title_tier < tier_empire
				}
			}
			OR = {
				is_powerful_vassal_of = title:e_byzantium.holder
				trigger_if = {
					limit = {
						government_allows = noble_families
					}
					house ?= { is_powerful_family = yes }
				}
				#Let's just always let Nikaea do this, they special
				capital_county = {
					kingdom = title:k_nikaea
					NOT = {
						exists = title:k_nikaea.holder
					}
				}
			}
		}
	}
	NOT = {
		government_has_flag = government_is_theocracy
	}
}

scripted_trigger ep3_frankokratia_events_0110_daddy_neighbor_trigger = {
	is_landed = yes
	highest_held_title_tier >= tier_duchy
	any_sub_realm_county = {
		any_neighboring_county = {
			OR = {
				holder = root
				holder.liege = root
				holder.liege.liege ?= root
			}
		}
	}
	OR = {
		#Higher tier
		highest_held_title_tier > root.highest_held_title_tier
		AND = {
			ep3_frankokratia_events_0110_potential_king_trigger = yes
			#Stronger military
			max_military_strength >= root.max_military_strength
		}
		AND = {
			ep3_frankokratia_events_0110_potential_king_trigger = yes
			#More counties
			sub_realm_size > root.sub_realm_size
		}
	}
	NOR = {
		highest_held_title_tier < root.highest_held_title_tier
		highest_held_title_tier < tier_duchy
		is_imprisoned = yes
		this = root
	}
	#If more than one option exists, second should always be admin
	trigger_if = {
		limit = {
			root = {
				government_has_mechanic = administrative
			}
			OR = {
				root = {
					is_landless_ruler = yes
				}
				exists = scope:daddy
			}
		}
		government_has_mechanic = administrative
	}
}

#Byzantine vassals hear about what's going on... and brace for what might come
ep3_frankokratia_events.0110 = {
	type = character_event
	title = ep3_frankokratia_events.0110.t
	desc = ep3_frankokratia_events.0110.desc
	theme = byzantine
	override_background = {
		reference = ep3_byzantium_throneroom
	}
	left_portrait = {
		character = scope:emperor
		triggered_animation = {
			trigger = { religion = religion:christianity_religion }
			animation = acknowledging # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	right_portrait = {
		character = scope:financier
		animation = manic
	}
	lower_center_portrait = scope:previous_holder
	lower_left_portrait = scope:daddy_2
	lower_right_portrait = scope:daddy
	immediate = {
		global_var:byz_claimant_champion = {
			random_owned_story = {
				type = frankokratia_story
				var:financier_title.holder = {
					save_scope_as = financier
				}
			}
		}
		save_scope_as = vassal
		#Save potential daddies of landed imperial vassal
		if = {
			limit = {
				is_vassal_of = scope:emperor
				is_landed = yes
				highest_held_title_tier < tier_kingdom
			}
			scope:emperor = {
				every_vassal = {
					limit = {
						this != root
						ep3_frankokratia_events_0110_daddy_neighbor_trigger = yes
					}
					add_to_list = potential_daddies
				}
			}
			#Try to grab neighbors
			if = {
				limit = {
					any_in_list = {
						list = potential_daddies
						highest_held_title_tier >= tier_kingdom
					}
				}
				ordered_in_list = {
					list = potential_daddies
					order_by = max_military_strength
					limit = {
						highest_held_title_tier >= tier_kingdom
					}
					save_scope_as = daddy
				}
			}
			else = {
				ordered_in_list = {
					list = potential_daddies
					order_by = max_military_strength
					save_scope_as = daddy
				}
			}
			#No one wants to lose admin status - try to grab same kingdom rulers
			if = {
				limit = {
					NOT = {
						exists = scope:daddy
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							this != root
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							capital_county.kingdom = root.capital_county.kingdom
							exists = root.house
							house ?= {
								this = root.house
							}
						}
						save_scope_as = daddy
					}
				}
			}
			if = {
				limit = {
					NOT = {
						exists = scope:daddy
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							this != root
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							exists = root.house
							house ?= {
								this = root.house
							}
						}
						save_scope_as = daddy
					}
				}
			}
			if = {
				limit = {
					NOT = {
						exists = scope:daddy
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							this != root
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							capital_county.kingdom = {
								any_de_jure_county = {
									any_neighboring_county = {
										kingdom = root.capital_county.kingdom
									}
								}
							}
						}
						save_scope_as = daddy
					}
				}
			}
			if = {
				limit = {
					NOT = {
						exists = scope:daddy
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							this != root
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							any_realm_county = {
								is_coastal_county = yes
							}
							root = {
								any_realm_county = {
									is_coastal_county = yes
								}
							}
						}
						save_scope_as = daddy
					}
				}
			}
			if = {
				limit = {
					any_in_list = {
						list = potential_daddies
						highest_held_title_tier >= tier_kingdom
					}
				}
				ordered_in_list = {
					list = potential_daddies
					order_by = realm_size
					limit = {
						highest_held_title_tier >= tier_kingdom
						this != scope:daddy
					}
					save_scope_as = daddy_2
				}
			}
			else = {
				ordered_in_list = {
					list = potential_daddies
					order_by = realm_size
					limit = {
						this != scope:daddy
					}
					save_scope_as = daddy_2
				}
			}
			#No one wants to lose admin status - try to grab same kingdom rulers
			if = {
				limit = {
					exists = scope:daddy
					NOT = {
						exists = scope:daddy_2
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							NOR = {
								this = root
								this = scope:daddy
							}
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							capital_county.kingdom = root.primary_title.kingdom
							exists = root.house
							house ?= {
								this = root.house
							}
						}
						save_scope_as = daddy_2
					}
				}
			}
			if = {
				limit = {
					exists = scope:daddy
					NOT = {
						exists = scope:daddy_2
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							NOR = {
								this = root
								this = scope:daddy
							}
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							exists = root.house
							house ?= {
								this = root.house
							}
						}
						save_scope_as = daddy_2
					}
				}
			}
			if = {
				limit = {
					exists = scope:daddy
					NOT = {
						exists = scope:daddy_2
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							NOR = {
								this = root
								this = scope:daddy
							}
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							capital_county.kingdom = {
								any_de_jure_county = {
									any_neighboring_county = {
										kingdom = root.primary_title.kingdom
									}
								}
							}
						}
						save_scope_as = daddy_2
					}
				}
			}
			if = {
				limit = {
					exists = scope:daddy
					NOT = {
						exists = scope:daddy_2
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							NOR = {
								this = root
								this = scope:daddy
							}
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							any_realm_county = {
								is_coastal_county = yes
							}
							root = {
								any_realm_county = {
									is_coastal_county = yes
								}
							}
						}
						save_scope_as = daddy_2
					}
				}
			}
		}
		#Sub vassal already has a daddy
		else_if = {
			limit = {
				liege.liege ?= {
					highest_held_title_tier < tier_empire
					this != root
				}
				is_landed = yes
			}
			liege.liege = {
				save_scope_as = daddy
			}
		}
		else_if = {
			limit = {
				is_landed = yes
				liege ?= {
					this != root
					highest_held_title_tier <= tier_kingdom
				}
			}
			liege = {
				save_scope_as = daddy
			}
		}
		#Save daddies for landless
		if = {
			limit = {
				is_landless_administrative = yes
			}
			#Relatives first
			if = {
				limit = {
					scope:emperor = {
						any_vassal = {
							this != root
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							exists = root.house
							house ?= {
								this = root.house
							}
						}
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							this != root
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							exists = root.house
							house ?= {
								this = root.house
							}
						}
						save_scope_as = daddy
					}
				}
			}
			#Vassals in same kingdom as estate
			else_if = {
				limit = {
					scope:emperor = {
						any_vassal = {
							this != root
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							exists = capital_county
							capital_county.kingdom = {
								this = root.domicile.domicile_location.county.kingdom
							}
						}
					}
				}
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							this != root
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
							exists = capital_county
							capital_county.kingdom = {
								this = root.domicile.domicile_location.county.kingdom
							}
						}
						save_scope_as = daddy
					}
				}
			}
			else = {
				scope:emperor = {
					ordered_vassal = {
						order_by = max_military_strength
						limit = {
							this != root
							ep3_frankokratia_events_0110_potential_king_trigger = yes
							NOT = {
								government_has_flag = government_is_theocracy
							}
						}
						save_scope_as = daddy
					}
				}
			}
			if = {
				limit = {
					exists = scope:daddy
				}
				#Relatives first for daddy 2
				if = {
					limit = {
						scope:emperor = {
							any_vassal = {
								NOR = {
									this = scope:daddy
									this = root
									government_has_flag = government_is_theocracy
								}
								ep3_frankokratia_events_0110_potential_king_trigger = yes
								exists = root.house
								house ?= {
									this = root.house
								}
							}
						}
					}
					scope:emperor = {
						ordered_vassal = {
							order_by = max_military_strength
							limit = {
								NOR = {
									this = scope:daddy
									this = root
									government_has_flag = government_is_theocracy
								}
								ep3_frankokratia_events_0110_potential_king_trigger = yes
								exists = root.house
								house ?= {
									this = root.house
								}
							}
							save_scope_as = daddy_2
						}
					}
				}
				#Vassals in same kingdom as estate
				else_if = {
					limit = {
						scope:emperor = {
							any_vassal = {
								NOR = {
									this = scope:daddy
									this = root
									government_has_flag = government_is_theocracy
								}
								ep3_frankokratia_events_0110_potential_king_trigger = yes
								exists = capital_county
								capital_county.kingdom = {
									this = root.domicile.domicile_location.county.kingdom
								}
							}
						}
					}
					scope:emperor = {
						ordered_vassal = {
							order_by = max_military_strength
							limit = {
								NOR = {
									this = scope:daddy
									this = root
									government_has_flag = government_is_theocracy
								}
								ep3_frankokratia_events_0110_potential_king_trigger = yes
								exists = capital_county
								capital_county.kingdom = {
									this = root.domicile.domicile_location.county.kingdom
								}
							}
							save_scope_as = daddy_2
						}
					}
				}
				else = {
					scope:emperor = {
						ordered_vassal = {
							order_by = max_military_strength
							limit = {
								NOR = {
									this = scope:daddy
									this = root
									government_has_flag = government_is_theocracy
								}
								ep3_frankokratia_events_0110_potential_king_trigger = yes
							}
							save_scope_as = daddy_2
						}
					}
				}
			}
		}
		if = {
			limit = {
				ep3_frankokratia_events_0110_potential_king_trigger = yes
			}
			capital_county = {
				kingdom = {
					save_scope_as = byz_kingdom
				}
			}
		}
	}
	#Powerful vassal - and want to maintain administrative government
	option = {
		trigger = {
			is_ai = no
			ep3_frankokratia_events_0110_potential_king_trigger = yes
		}
		name = ep3_frankokratia_events.0110.a
		add_internal_flag = special
		#If you are the emperor's favorite vassal, he flees to join you
		if = {
			limit = {
				ep3_frankokratia_events_0110_favorite_vassal_trigger = yes
			}
			custom_tooltip = previous_emp_will_join_court_tt
		}
		custom_description_no_bullet = {
		 	text = if_byz_dissolves_tt
		 	subject = root
		}
		if = {
			limit = {
				highest_held_title_tier < tier_kingdom
			}
			custom_tooltip = gain_byz_kingdom_tt
		}
		if = {
			limit = {
				government_has_mechanic = administrative
			}
			custom_tooltip = byz_remain_admin_tt
		}
		custom_tooltip = byz_vassals_may_join_tt
		custom_tooltip = byz_become_independent_tt
		if = {
			limit = {
				NOT = {
					highest_held_title_tier = tier_kingdom
				}
			}
			set_variable = {
				name = frankokratia_becoming_king
				value = yes
				days = 60
			}
		}
		if = {
			limit = {
				exists = scope:daddy
			}
			stress_and_fulfillment_impact = {
				humble = medium_stress_impact_gain
				craven = medium_stress_impact_gain
				content = minor_stress_impact_gain
			}
		}
		#Once all player vassals have this flag, Latin Empire chain can proceed
		add_character_flag = {
			flag = byz_aftermath_fate
			years = 1
		}
	}
	#Want to be under a more powerful neighbor
	option = {
		trigger = {
			is_ai = no
			exists = scope:daddy
			highest_held_title_tier < tier_kingdom
		}
		name = ep3_frankokratia_events.0110.b
		#If you are the emperor's favorite vassal, he flees to join you
		if = {
			limit = {
				ep3_frankokratia_events_0110_favorite_vassal_trigger = yes
			}
			custom_tooltip = previous_emp_will_join_court_tt
		}
		custom_description_no_bullet = {
		 	text = if_byz_dissolves_tt
		 	subject = root
		}
		if = {
			limit = {
				NOR = {
					liege = scope:daddy
					liege.liege ?= scope:daddy
				}
			}
			custom_tooltip = become_daddys_vassal_tt
		}
		else = {
			custom_tooltip = remain_daddys_vassal_tt
		}
		if = {
			limit = {
				government_has_mechanic = administrative
				scope:daddy = {
					government_has_mechanic = administrative
					ep3_frankokratia_events_0110_potential_king_trigger = yes
				}
			}
			custom_tooltip = byz_remain_admin_tt
		}
		else_if = {
			limit = {
				government_has_mechanic = administrative
			}
			custom_tooltip = byz_become_feudal_or_clan_tt
			custom_tooltip = frankokratia_lose_domicile_tt
		}
		scope:daddy = {
			set_variable = {
				name = frankokratia_gaining_vassal
				value = root
				days = 60
			}
		}
		if = {
			limit = {
				is_landed = yes
			}
			stress_and_fulfillment_impact = {
				ambitious = minor_stress_impact_gain
				arrogant = medium_stress_impact_gain
				fickle = minor_stress_impact_gain
				brave = miniscule_stress_impact_gain
			}
		}
		else = {
			hidden_effect = {
				domicile = {
					move_domicile = scope:daddy.capital_province
				}
			}
		}
		#Once all player vassals have this flag, Latin Empire chain can proceed
		add_character_flag = {
			flag = byz_aftermath_fate
			years = 1
		}
	}
	#Want to be under a different more powerful neighbor
	option = {
		trigger = {
			is_ai = no
			exists = scope:daddy_2
			highest_held_title_tier < tier_kingdom
		}
		name = ep3_frankokratia_events.0110.c
		#If you are the emperor's favorite vassal, he flees to join you
		if = {
			limit = {
				ep3_frankokratia_events_0110_favorite_vassal_trigger = yes
			}
			custom_tooltip = previous_emp_will_join_court_tt
		}
		custom_description_no_bullet = {
		 	text = if_byz_dissolves_tt
		 	subject = root
		}
		if = {
			limit = {
				NOR = {
					liege = scope:daddy_2
					liege.liege ?= scope:daddy_2
				}
			}
			custom_tooltip = become_daddy_2_vassal_tt
		}
		else = {
			custom_tooltip = remain_daddy_2_vassal_tt
		}
		if = {
			limit = {
				government_has_mechanic = administrative
				scope:daddy_2 = {
					government_has_mechanic = administrative
					ep3_frankokratia_events_0110_potential_king_trigger = yes
				}
			}
			custom_tooltip = byz_remain_admin_tt
		}
		else_if = {
			limit = {
				government_has_mechanic = administrative
			}
			custom_tooltip = byz_become_feudal_or_clan_tt
			custom_tooltip = frankokratia_lose_domicile_tt
		}
		scope:daddy_2 = {
			set_variable = {
				name = frankokratia_gaining_vassal
				value = root
				days = 60
			}
		}
		if = {
			limit = {
				is_landed = yes
			}
			stress_and_fulfillment_impact = {
				ambitious = minor_stress_impact_gain
				arrogant = medium_stress_impact_gain
				fickle = minor_stress_impact_gain
				brave = miniscule_stress_impact_gain
			}
		}
		else = {
			hidden_effect = {
				domicile = {
					move_domicile = scope:daddy_2.capital_province
				}
			}
		}
		#Once all player vassals have this flag, Latin Empire chain can proceed
		add_character_flag = {
			flag = byz_aftermath_fate
			years = 1
		}
	}
	#Want to be independent
	option = {
		trigger = {
			is_ai = no
			is_landed = yes
		}
		name = ep3_frankokratia_events.0110.d
		#If you are the emperor's favorite vassal, he flees to join you
		if = {
			limit = {
				ep3_frankokratia_events_0110_favorite_vassal_trigger = yes
			}
			custom_tooltip = previous_emp_will_join_court_tt
		}
		custom_description_no_bullet = {
		 	text = if_byz_dissolves_tt
		 	subject = root
		}
		custom_tooltip = byz_become_independent_tt
		if = {
			limit = {
				government_has_mechanic = administrative
			}
			custom_tooltip = byz_become_feudal_or_clan_tt
			custom_tooltip = frankokratia_lose_domicile_tt
		}
		set_variable = {
			name = frankokratia_independent
			value = yes
			days = 60
		}
		if = {
			limit = {
				exists = scope:daddy
			}
			stress_and_fulfillment_impact = {
				trusting = minor_stress_impact_gain
				humble = minor_stress_impact_gain
				craven = medium_stress_impact_gain
				content = medium_stress_impact_gain
			}
		}
		#Once all player vassals have this flag, Latin Empire chain can proceed
		add_character_flag = {
			flag = byz_aftermath_fate
			years = 1
		}
	}
	#AI option that does nothing
	option = {
		trigger = {
			is_ai = yes
		}
	}
	after = {
		if = {
			limit = {
				ep3_frankokratia_events_0110_favorite_vassal_trigger = yes
			}
			trigger_event = {
				id = ep3_frankokratia_events.0111
				days = 10
			}
		}
	}
}

ep3_frankokratia_events.0111 = {
	hidden = yes
	immediate = {
		if = {
			limit = {
				scope:previous_holder = {
					is_alive = yes
					is_imprisoned = no
					is_incapable = no
					is_landed = no
					is_landless_ruler = no
				}
				is_landed = yes
			}
			send_interface_message = {
				type = msg_frankokratia_former_emp_courtier
				title = frankokratia_former_emp_courtier.t
				left_icon = scope:previous_holder
				add_courtier = scope:previous_holder
				scope:previous_holder = {
					every_consort = {
						limit = {
							is_ruler = no
							is_imprisoned = no
						}
						root = {
							add_courtier = prev
						}
					}
				}
				scope:previous_holder = {
					every_child = {
						limit = {
							is_ruler = no
							is_imprisoned = no
							is_adult = no
							is_hostage = no
							is_foreign_court_guest = no
						}
						root = {
							add_courtier = prev
						}
					}
				}
			}
		}
	}
}

#Latin Emperor considers adopting Byzantine admin government
ep3_frankokratia_events.0120 = {
	type = character_event
	title = ep3_frankokratia_events.0120.t
	desc = {
		first_valid = {
			triggered_desc = {
				trigger = {
					capital_county = title:c_byzantion
				}
				desc = ep3_frankokratia_events.0120.hippodrome
			}
			desc = ep3_frankokratia_events.0120.estate
		}
		desc = ep3_frankokratia_events.0120.desc
	}
	theme = administrative
	override_background = {
		trigger = {
			capital_county = title:c_byzantion
		}
		reference = ep3_hippodrome
	}
	override_background = {
		trigger = {
			NOT = { capital_county = title:c_byzantion }
		}
		reference = estate
	}
	left_portrait = {
		character = root
		animation = inspect_weapon
		camera = camera_event_left_away_3_4
	}
	right_portrait = {
		character = scope:eunuch
		animation = obsequious_bow
		camera = camera_event_right_pointing_right
	}
	trigger = {
		has_ep3_dlc_trigger = yes
		government_has_flag = government_is_feudal
		title:e_latin_empire.holder ?= this
		is_alive = yes
		is_imprisoned = no
	}
	on_trigger_fail = {
		title:e_latin_empire.holder ?= {
			if = {
				limit = { government_has_flag = government_is_feudal }
				trigger_event = {
					id = ep3_frankokratia_events.0120
					days = 90
				}
			}
		}
	}
	immediate = {
		add_character_flag = {
			flag = latin_emp_force_admin_flag
			days = 30
		}

		#find a eunuch to present this whole thing
		if = {
			limit = {
				any_vassal = {
					has_trait = eunuch
					is_available_ai_adult = yes
					OR = {
						culture = culture:greek
						culture = {
							any_parent_culture_or_above = {
								this = culture:greek
							}
						}
					}
					ep3_orthodox_faith_trigger = yes
				}
			}
			random_vassal = {
				limit = {
					has_trait = eunuch
					is_available_ai_adult = yes
					OR = {
						culture = culture:greek
						culture = {
							any_parent_culture_or_above = {
								this = culture:greek
							}
						}
					}
					ep3_orthodox_faith_trigger = yes
				}
				save_scope_as = eunuch
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:eunuch
				}
			}
			random_courtier = {
				limit = {
					has_trait = eunuch
					is_available_ai_adult = yes
					OR = {
						culture = culture:greek
						culture = {
							any_parent_culture_or_above = {
								this = culture:greek
							}
						}
					}
					ep3_orthodox_faith_trigger = yes
				}
				save_scope_as = eunuch
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:eunuch
				}
			}
			random_courtier = {
				limit = {
					has_trait = eunuch
					is_available_ai_adult = yes
					OR = {
						culture = culture:greek
						culture = {
							any_parent_culture_or_above = {
								this = culture:greek
							}
						}
						ep3_orthodox_faith_trigger = yes
					}
				}
				save_scope_as = eunuch
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:eunuch
				}
			}
			random_pool_guest = {
				limit = {
					has_trait = eunuch
					is_available_ai_adult = yes
					OR = {
						culture = culture:greek
						culture = {
							any_parent_culture_or_above = {
								this = culture:greek
							}
						}
						ep3_orthodox_faith_trigger = yes
					}
				}
				save_scope_as = eunuch
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:eunuch
				}
			}
			random_pool_character = {
				province = root.capital_province
				limit = {
					has_trait = eunuch
					is_available_ai_adult = yes
					OR = {
						culture = culture:greek
						culture = {
							any_parent_culture_or_above = {
								this = culture:greek
							}
						}
						ep3_orthodox_faith_trigger = yes
					}
				}
				save_scope_as = eunuch
			}
		}
		if = {
			limit = {
				NOT = {
					exists = scope:eunuch
				}
			}
			create_character = {
				location = root.capital_province
				culture = root.capital_province.culture
				faith = root.capital_province.faith
				rite = root.capital_province.rite
				template = random_learned_eunuch_character
				save_scope_as = eunuch
			}
		}
	}
	#There is one thing about those Byzantines I like...
	option = {
		name = ep3_frankokratia_events.0120.a
		flavor = ep3_frankokratia_events.0120.a.flavor
		trigger = {
			OR = {
				has_trait = wrathful
				has_trait = callous
				has_trait = sadistic
				has_trait = vengeful
				has_trait = arrogant
				has_trait = arbitrary
				has_trait = greedy
			}
			scope:eunuch = {
				OR = {
					NOT = {
						has_trait = blind
					}
					NOT = {
						has_trait = disfigured
					}
				}
			}
		}
		custom_tooltip = emulating_byz_punishment_tt
		title:e_latin_empire = {
			set_variable = {
				name = emulating_byz_punishment_var
				value = yes
			}
		}
		save_scope_as = latin_emp
		add_character_flag = {
			flag = frankokratia_torture_greeks_flag
			days = 60
		}
		every_vassal_or_below = {
			limit = {
				highest_held_title_tier >= tier_county
				NOT = {
					is_at_war_with = root
				}
			}
			save_scope_as = latin_vassal
			trigger_event = ep3_frankokratia_events.0121
		}

		scope:eunuch = {
			if = {
				limit = {
					NOT = {
						has_trait = blind
					}
				}
				add_trait = blind
				add_opinion = {
					modifier = blinded_me
					target = root
				}
			}
			else = {
				add_trait = disfigured
				add_opinion = {
					modifier = disfigured_me
					target = root
				}
			}
			every_close_family_member = {
				custom = all_close_family_and_spouses
				limit = {
					this != root
				}
				add_opinion = {
					target = root
					modifier = blinded_family_member
				}
			}
			hidden_effect = {
				scope:eunuch = {
					every_spouse = {
						limit = {
							this != root
						}
						add_opinion = {
							target = root
							modifier = blinded_family_member
						}
					}
				}
			}
		}
		add_dread = major_dread_gain
		add_prestige = medium_prestige_gain
		add_gold = monumental_gold_value
		stress_and_fulfillment_impact = {
			compassionate = major_stress_impact_gain
			forgiving = major_stress_impact_gain
			trusting = minor_stress_impact_gain
			humble = minor_stress_impact_gain
			just = minor_stress_impact_gain
		}
		ai_chance = {
			base = 200
			ai_value_modifier = {
				ai_compassion = -1
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = compassionate
					has_trait = forgiving
				}
			}
		}
	}
	#Become admin
	option = {
		name = ep3_frankokratia_events.0120.b
		flavor = ep3_frankokratia_events.0120.b.flavor
		capital_county.kingdom = {
			set_de_jure_liege_title = title:e_latin_empire
		}
		custom_tooltip = greeks_more_likely_to_vassalize_tt
		# Give Acclamation succession
		if = {
			limit = {
				has_dlc_feature = admin_gov
			}
			add_realm_law_skip_effects = acclamation_succession_law
			convert_to_administrative_from_feudalism_effect = { GOVERNMENT_TO_ADOPT = flag:administrative }

			create_character_memory = {
				type = frankokratia_latin_admin_memory
			}
			#Letter event for the vassals
			trigger_event = ep3_decisions_event.4060 #Also sends information event to human vassals
		}
		else_if = {
			limit = {
				has_realm_law = crown_authority_0
			}
			add_realm_law = crown_authority_1
		}
		else_if = {
			limit = {
				has_realm_law = crown_authority_1
			}
			add_realm_law = crown_authority_2
		}
		else_if = {
			limit = {
				has_realm_law = crown_authority_2
			}
			add_realm_law = crown_authority_3
		}
		
		if = {
			limit = {
				is_independent_ruler = yes
			}
			add_legitimacy_effect = { LEGITIMACY = admin_convert_legitimacy_value } #One Time Legitimacy Boost
		}
		
		if = {
			limit = {
				scope:eunuch = {
					NOT = {
						is_courtier_of = root
					}
					is_landed = no
				}
			}
			add_courtier = scope:eunuch
		}
		#Gain Greek opinion
		#Your vassals should mostly do it, but be really pissed
		add_character_modifier = {
			modifier = latin_emp_simp_modifier
			years = 10
		}
		stress_and_fulfillment_impact = {
			stubborn = medium_stress_impact_gain
			paranoid = minor_stress_impact_gain
			arbitrary = minor_stress_impact_gain
			content = minor_stress_impact_gain
		}

		ai_chance = {
			base = 50
			ai_value_modifier = {
				ai_rationality = 0.5
				ai_boldness = -0.5
			}
			modifier = {
				factor = 0
				OR = {
					has_trait = stubborn
					has_trait = forgiving
				}
			}
		}
	}
	#Yeah... nah. We feudal knights
	option = {
		name = ep3_frankokratia_events.0120.c
		flavor = ep3_frankokratia_events.0120.c.flavor

		save_scope_as = latin_emp
		#Your vassals appreciate you boo
		every_vassal = {
			custom = custom.every_vassal
			limit = {
				NOT = {
					is_at_war_with = root
				}
			}
			save_scope_as = latin_vassal
			add_opinion = {
				target = root
				modifier = pleased_opinion
				opinion = 20
			}
			show_as_tooltip = {
				add_gold = 40
			}
			trigger_event = ep3_frankokratia_events.0121
		}
		add_prestige = medium_prestige_gain
		add_piety = medium_piety_gain
		add_gold = massive_gold_value
		ai_chance = {
			base = 100
			ai_value_modifier = {
				ai_greed = 0.5
				ai_rationality = -0.5
			}
		}
	}
	after = {
		remove_character_flag = latin_emp_force_admin_flag
	}
}

#Latin Emperor writes to vassals
ep3_frankokratia_events.0121 = {
	type = letter_event
	opening = {
		desc = ep3_frankokratia_events.0121.opening
	}
	desc = {
		desc = ep3_frankokratia_events.0121.intro
		first_valid = {
			triggered_desc = {
				trigger = {
					has_character_flag = frankokratia_torture_greeks_flag
				}
				desc = ep3_frankokratia_events.0121.desc_torture
			}
			desc = ep3_frankokratia_events.0121.desc
		}
	}

	sender = scope:latin_emp

	immediate = {
	}
	option = {
		name = ep3_frankokratia_events.0121.a
		flavor = ep3_frankokratia_events.0121.a.flavor
		scope:latin_vassal = {
				if = {
				limit = {
					has_character_flag = frankokratia_torture_greeks_flag
				}
				custom_tooltip = emulating_byz_punishment_tt
				add_dread = minor_dread_gain
			}
			else = {
				add_gold = 40
				capital_county = {
					change_development_progress = medium_development_progress_loss
				}
			}
		}
	}
}

#THE BYZ IS BACK
#ITS BYZZTTNEY BITCH
ep3_frankokratia_events.0130 = {
	type = character_event
	title = ep3_frankokratia_events.0130.t
	desc = {
		desc = ep3_frankokratia_events.0130.desc
		first_valid = {
			triggered_desc = {
				trigger = {
					exists = scope:latin_emperor
				}
				desc = ep3_frankokratia_events.0130.latin_emp
			}
			desc = ep3_frankokratia_events.0130.unopposed
		}
	}
	theme = byzantine
	override_background = {
		trigger = {
			scope:byz_emperor = {
				capital_county = title:c_byzantion
			}
		}
		reference = ep3_hagia_sophia
	}
	override_background = {
		trigger = {
			NOT = {
				scope:byz_emperor = {
					capital_county = title:c_byzantion
				}
			}
		}
		reference = ep3_byzantium_throneroom
	}
	override_effect_2d = {
		reference = legend_glow
	}
	left_portrait = {
		character = scope:byz_emperor
		triggered_animation = {
			trigger = { religion = religion:christianity_religion }
			animation = scepter # anim uses crucifix scepter
		}
		animation = war_over_tie
	}
	lower_right_portrait = scope:latin_emperor
	immediate = {
		if = {
			limit = {
				title:e_latin_empire = {
					holder ?= {
						NOT = {
							any_held_title = {
								this = title:e_byzantium
							}
						}
					}
				}
			}
			title:e_latin_empire.holder = {
				save_scope_as = latin_emperor
			}
		}
	}
	option = {
		name = ep3_frankokratia_events.0130.a
	}
}

#Hidden event that makes latin empire de jure for struggling emp
ep3_frankokratia_events.0140 = {
	hidden = yes
	immediate = {
		capital_county.kingdom = {
			set_de_jure_liege_title = title:e_latin_empire
			save_scope_as = swapped_kingdom
		}
		#Send notification out to everyone in de jure latin empire
		if = {
			limit = {
				title:e_latin_empire = {
					any_in_de_jure_hierarchy = {
						holder ?= {
							is_ai = no
						}
					}
				}
			}
			title:e_latin_empire = {
				every_in_de_jure_hierarchy = {
					limit = {
						holder ?= {
							is_ai = no
						}
					}
					if = {
						limit = {
							holder ?= {
								NOT = { is_in_list = latin_byz_notify }
							}
						}
						holder = {
							add_to_list = latin_byz_notify
						}
					}
				}
			}
		}
		if = {
			limit = {
				title:e_byzantium = {
					any_in_de_jure_hierarchy = {
						holder ?= {
							is_ai = no
						}
					}
				}
			}
			title:e_byzantium = {
				every_in_de_jure_hierarchy = {
					limit = {
						holder ?= {
							is_ai = no
						}
					}
					if = {
						limit = {
							holder = {
								NOT = { is_in_list = latin_byz_notify }
							}
						}
						holder = {
							add_to_list = latin_byz_notify
						}
					}
				}
			}
		}
		title:e_latin_empire.holder = {
			if = {
				limit = {
					NOT = { is_in_list = latin_byz_notify }
				}
				add_to_list = latin_byz_notify
			}
			trigger_event = ep3_frankokratia_events.0081
		}
	}
}
